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

namespace Intrepid.Gameplay.Entities.Player.PDA.UI.Applications.MusicPlayer
{
    public class PDAMusicPlayerAppUI : PDAApplicationUI
    {
        [SerializeField] private PDAMusicSelectionUI musicSelection;
        [SerializeField] private PDAMusicPlayerUI musicPlayer;
        
        public override bool IsLoading => false;

        public override void UpdateTheme()
        {
        }

        public override void UpdateApplication(PDAInputs inputs)
        {
            if (inputs.Cancel())
            {
                Proxy.Instance.EventBus.Raise(new PDAExitCurrentApplicationEvent());
            }

            musicSelection.UpdateApplication(inputs);
            if (inputs.DPad.Down())
            {
                SelectedMusic();
            }
            musicPlayer.UpdateApplication(inputs);
        }

        public override void LateUpdateApplication(PDAInputs inputs)
        {
        }

        protected override void Subscribing()
        {
        }

        protected override void WhenStarting(ParameterStore parameters)
        {
            musicSelection.Feed(Device.GetMusicKnown());
            musicSelection.WhenStarting();
            musicPlayer.WhenStarting();
        }

        protected override void WhenFinishing()
        {
            musicSelection.WhenFinishing();
            musicPlayer.WhenFinishing();
        }

        public void SelectedMusic()
        {
            musicPlayer.SelectedMusic(musicSelection.SelectedMusic);
        }
    }
}