using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class UIManagerMenu : Manager<UIManagerMenu>
{
    [SerializeField]
    private Slider audioVolumeSlider;

    [SerializeField]
    private Button playButton;

    private void OnGameStateChanged(GameState newState, GameState oldState)
    {
        if(newState == GameState.Play)
        {
            this.gameObject.SetActive(false);
        }

        if(newState == GameState.Menu)
        {
            this.gameObject.SetActive(true);
        }
    }

    protected void Start()
    {
        GameStateManager.Instance.OnGameStateChangedEvent.AddListener(this.OnGameStateChanged);

        playButton.onClick.AddListener(OnPlayButtonClicked);

        audioVolumeSlider.value = PersistantStorage.Instance.AudioVolume;
    }

    protected void Update()
    {
        PersistantStorage.Instance.AudioVolume = audioVolumeSlider.value;
    }

    protected void OnDestroy()
    {
        GameStateManager.Instance.OnGameStateChangedEvent.RemoveListener(this.OnGameStateChanged);
    }

    private void OnPlayButtonClicked()
    {
        GameStateManager.Instance.SetGameState(GameState.Play);
    }
}
