using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace BulletHellTemplate
{
    /// 
    /// Represents a UI entry for a character skin.
    /// 
    public class SkinEntry : MonoBehaviour
    {
        [Tooltip("Image displaying the skin icon.")]
        public Image skinIcon;
        [Tooltip("Image indicating if the skin is locked.")]
        public Image lockedSkin;
        [Tooltip("Image indicating if the skin is selected.")]
        public Image selectedSkin;
        [Tooltip("Text displaying the skin name.")]
        public TextMeshProUGUI skinName;
        private int skinIndex;
        /// 
        /// Configures the SkinEntry with the given skin data.
        /// 
        /// The character skin data.
        /// The index of the skin.
        /// Indicates if the skin is unlocked.
        public void SetupSkinEntry(CharacterSkin skin, int index, bool isUnlocked)
        {
            skinIndex = index;
            if (skinIcon != null)
                skinIcon.sprite = skin.skinIcon;
            string currentLang = LanguageManager.LanguageManager.Instance.GetCurrentLanguage();
            skinName.text = UICharacterMenu.Singleton.GetTranslatedString(skin.skinNameTranslated, skin.skinName, currentLang);
            if (lockedSkin != null)
                lockedSkin.gameObject.SetActive(!isUnlocked);
        }
        /// 
        /// Handles the selection of this skin.
        /// 
        public void OnClickSelectSkin()
        {
            if (UICharacterMenu.Singleton != null)
            {
                 UICharacterMenu.Singleton.ChangeCharacterSkin(skinIndex);
                if (UICharacterMenu.Singleton.UISkins != null)
                    UICharacterMenu.Singleton.UISkins.SetActive(false);
            }
        }
    }
}