using Nox.Core;

namespace Nox.Game.UI {
    public class AdventureView : IMenuView {
        private readonly GameDataState gameDataState;
        private readonly GuiReferences guiReferences;
        private readonly InputSystem_Actions inputActions;
        private readonly AdventureData adventureData;
        private readonly AdventureSettings adventureSettings;
        private DayPhase dayPhase = DayPhase.Midnight;
        private int currentDay;

        public AdventureView(
            GameDataState gameDataState,
            GuiReferences guiReferences,
            InputSystem_Actions inputActions,
            AdventureData adventureData,
            AdventureSettings adventureSettings) {
            this.gameDataState = gameDataState;
            this.guiReferences = guiReferences;
            this.inputActions = inputActions;
            this.adventureData = adventureData;
            this.adventureSettings = adventureSettings;
        }
        private void InvokePauseMenu() {
            gameDataState.ChangePlayMode(PlayMode.PauseMenu);
        }

        public void Initialize() {
            guiReferences.pauseMenuButton.onClick.AddListener(InvokePauseMenu);
            guiReferences.dayText.text = $"Day {adventureData.currentDay}, {adventureData.currentDayPhase.ToString()}";
            guiReferences.suppliesBar.fillAmount = (float)adventureData.suppliesAvailable / adventureSettings.maxSupplies;
            guiReferences.suppliesText.text = $"{adventureData.suppliesAvailable}/{adventureSettings.maxSupplies}";
        }

        public void Show() {
            throw new System.NotImplementedException();
        }
        public void Hide() {
            throw new System.NotImplementedException();
        }
        public void Tick() {
            if(dayPhase != adventureData.currentDayPhase) {
                dayPhase = adventureData.currentDayPhase;
                guiReferences.dayText.text = $"Day {adventureData.currentDay}, {adventureData.currentDayPhase.ToString()}";
            }

            if(currentDay != adventureData.currentDay) {
                currentDay = adventureData.currentDay;
                guiReferences.dayText.text = $"Day {adventureData.currentDay}, {adventureData.currentDayPhase.ToString()}";
                guiReferences.suppliesBar.fillAmount = (float)adventureData.suppliesAvailable / adventureSettings.maxSupplies;
                guiReferences.suppliesText.text = $"{adventureData.suppliesAvailable}/{adventureSettings.maxSupplies}";
            }
        }
    }
}
