using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class AbilityBindInstance : MonoBehaviour
{
    public GameKey gameKey;

    [SerializeField] private GameEventListener_AbilityKeyBinder onAbilityKeyBinderSpawned;
    public TMP_Text bind;
    public TMP_Text manaCost;
    public Image icon;
    public GameObject noMana;
    public GameObject pressed;

    [Header("Set by Code:")]
    public AbilityKeyBinder abilityKeyBinder;

    private void Awake()
    {
        onAbilityKeyBinderSpawned.Response.AddListener(InitializeAbilityBindInstance);
    }

    public void InitializeAbilityBindInstance(AbilityKeyBinder abilityKeyBinder)
    {
        if (abilityKeyBinder.GameKey != gameKey) return;

        this.abilityKeyBinder = abilityKeyBinder;
        string keyName = gameKey.keyCode.ToString();
        //alpha
        keyName = keyName.Remove(0, 5);
        this.bind.text = keyName;
        this.manaCost.text = abilityKeyBinder.Ability.manaCost.ToString();
        this.icon.sprite = abilityKeyBinder.Ability.Icon;
        noMana.SetActive(false);
        pressed.SetActive(false);

        abilityKeyBinder.SetupAbilityBindInstance(this);
    }
}
