using UnityEngine;
using UnityEngine.SceneManagement;
public class UIManagerIntro : MonoBehaviour
{
    public static UIManagerIntro Instance;
    public GameObject pauseMenu;   
    
    public bool isPaused;

    void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
            return;
        }

        Instance = this;
        DontDestroyOnLoad(gameObject);
    }

    void Start()
    {
        SetPaused(false);
        if (pauseMenu) pauseMenu.SetActive(false);
    }

    void Update()
    {
        // toggle pause with Escape
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            TogglePause();
        }
    }

    public void TogglePause()
    {
        SetPaused(!isPaused);
    }

    public void SetPaused(bool paused)
    {
        isPaused = paused;
        if (pauseMenu) pauseMenu.SetActive(paused);
        Time.timeScale = paused ? 0f : 1f;
    }

    public void OnUnpauseButton() => SetPaused(false);

    //TODO this button from win screen doesnt restard fully. 
    public void OnRestartButton()
    {
        Time.timeScale = 1f;
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }

    public void OnMainMenuButton(string mainMenuSceneName)
    {
        Time.timeScale = 1f;
        SceneManager.LoadScene(mainMenuSceneName);
    }

    public bool GetIsPaused()
    {
        return isPaused;
    }
}
