using Actions;
using TMPro;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;

namespace UI {
    public class ActionButtonUI : MonoBehaviour {
        [FormerlySerializedAs("TextMeshPro")] [SerializeField] private TextMeshProUGUI textMeshPro;
        [FormerlySerializedAs("Button")] [SerializeField] private Button button;
        [FormerlySerializedAs("SelectedGameObject")] [SerializeField] private GameObject selectedGameObject;

        private BaseAction baseAction;

        public void SetBaseAction(BaseAction newBaseAction) {
            baseAction = newBaseAction;
            textMeshPro.text = newBaseAction.ActionName;
            button.onClick.AddListener(() => UnitActionSystem.Instance.SetSelectedAction(newBaseAction));
        }

        public void UpdateSelectedVisual() => selectedGameObject.SetActive(UnitActionSystem.Instance.SelectedAction == baseAction);
    }
}