using Intrepid.GameManagers;
using Intrepid.Gameplay.Entities.Player.PDA.Events;
using Intrepid.Gameplay.Entities.Player.PDA.Inputs;
using Intrepid.Gameplay.Themes;
using Intrepid.Structures;
using Intrepid.Utilities;
using UnityEngine;
using UnityEngine.UI;

namespace Intrepid.Gameplay.Entities.Player.PDA.UI.Applications.ThemeChanger
{
    public class PDAThemeChangerAppUI : PDAApplicationUI
    {
        [GroupInjections, SerializeField] private ThemeSelectionAreaUI currentThemeSelectionAreaUI;
        [GroupInjections, SerializeField] private ThemeSelectorUI themeSelectorUI;
        [GroupInjections, SerializeField] private Image background;

        public override bool IsLoading => false;
        
        public override void UpdateTheme()
        {
            currentThemeSelectionAreaUI.Theme = ThemeManager.Instance.CurrentTheme;
            background.color = currentThemeSelectionAreaUI.Theme.PDAThemes.AppTheme.Background;
        }
        
        public override void UpdateApplication(PDAInputs inputs)
        {
            if (inputs.Cancel())
            {
                Proxy.Instance.EventBus.Raise(new PDAExitCurrentApplicationEvent());
            }

            if (inputs.DPad.Up())
            {
                themeSelectorUI.SwitchUp();
            }
            
            if (inputs.DPad.Down())
            {
                themeSelectorUI.SwitchDown();
            }

            if (inputs.Enter())
            {
                themeSelectorUI.Select();
                currentThemeSelectionAreaUI.Operational(true);
            }
        }
        
        public override void LateUpdateApplication(PDAInputs inputs)
        {
            currentThemeSelectionAreaUI.Operational();
        }

        protected override void Subscribing()
        {
            
        }

        protected override void WhenStarting(ParameterStore parameters)
        {
            themeSelectorUI.Load(Device);
        }

        protected override void WhenFinishing()
        {
            
        }
    }
}