using UnityEngine;
using UnityEngine.UIElements;

namespace VOID.UserInterface.Game
{
    public class ActionBarMiniMenuUI : MonoBehaviour
    {
        public static ActionBarMiniMenuUI current {get; private set;}
        
        // Visual Elements - Mini menu
        private Button _menuButton;
        private Button _backpackButton;
        private Button _equipmentButton;
        private Button _abilityBookButton;
        private Button _mapButton;
        private Button _logBookButton;
        
        // References
        private BackpackUI _backpackUI;
        private EquipmentUI _equipmentUI;
        private AbilityBookUI _abilityBookUI;
        
        private void Awake()
        {
            current = this;

            var uiDocument = gameObject.GetComponent<UIDocument>();
            var templateElement = uiDocument.rootVisualElement;
            
            // Find all important elements
            _menuButton = templateElement.Q<Button>("menu");
            _backpackButton = templateElement.Q<Button>("backpack");
            _equipmentButton = templateElement.Q<Button>("equipment");
            _abilityBookButton = templateElement.Q<Button>("ability-book");
            _mapButton = templateElement.Q<Button>("map");
            _logBookButton = templateElement.Q<Button>("log-book");

            _menuButton.dataSource = this;
            _menuButton.pickingMode = PickingMode.Position;
        }

        private void Start()
        {
            _backpackUI = BackpackUI.current;
            _equipmentUI = EquipmentUI.current;
            _abilityBookUI = AbilityBookUI.current;
            
            // Bind show/hide toggle buttons in mini menu for all UI
            _backpackButton.clicked += _backpackUI.Toggle;
            _equipmentButton.clicked += _equipmentUI.Toggle;
            _abilityBookButton.clicked += _abilityBookUI.Toggle;
            _menuButton.clicked += PauseMenuUI.current.Toggle;
            // _mapButton.clicked += ???.current.Toggle;
            // _logBookButton.clicked += ???.current.Toggle;
            _menuButton.clicked += () => Debug.LogWarning("Shortcut for <b>Menu</b> not implemented");
            _mapButton.clicked += () => Debug.LogWarning("Shortcut for <b>Map</b> not implemented");
            _logBookButton.clicked += () => Debug.LogWarning("Shortcut for <b>Log Book</b> not implemented");
        }
    }
}
