#if INPUTSYSTEM_SUPPORT
using AlicizaX.UI.Runtime;
using UnityEngine;

namespace AlicizaX.UI
{
    // [DisallowMultipleComponent]
    public class HotkeyBindComponent : MonoBehaviour
    {
        private UIHolderObjectBase _holderObjectBase;

        private void Awake()
        {
            _holderObjectBase = GetComponent<UIHolderObjectBase>();
            _holderObjectBase.OnWindowBeforeShowEvent += BindHotKeys;
            _holderObjectBase.OnWindowBeforeClosedEvent += UnBindHotKeys;
        }

        private void OnDestroy()
        {
            _holderObjectBase.OnWindowBeforeShowEvent -= BindHotKeys;
            _holderObjectBase.OnWindowBeforeClosedEvent -= UnBindHotKeys;
        }

        [SerializeField] private UXHotkeyButton[] hotButtons;

        internal void BindHotKeys()
        {
            for (int i = 0; i < hotButtons.Length; i++)
            {
                hotButtons[i].BindHotKey();
            }
        }

#if UNITY_EDITOR
        [ContextMenu("Bind HotKeys")]
        private void CollectUXHotkeys()
        {
            hotButtons = gameObject.GetComponentsInChildren<UXHotkeyButton>(true);
        }
#endif

        internal void UnBindHotKeys()
        {
            for (int i = 0; i < hotButtons.Length; i++)
            {
                hotButtons[i].UnBindHotKey();
            }
        }
    }
}

#endif
