using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.EventSystems;

public class PauseMenu : MonoBehaviour
{
    public GameObject pauseMenuPanel;

    //public GameObject resumeButton;

    public bool isGamePaused { get; private set; }

    //EventSystem eventSystem;

    private void Awake()
    {
        //eventSystem = EventSystem.current;

        pauseMenuPanel.SetActive(false);
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (isGamePaused) { p_ContinueGame(); }
            else if (!isGamePaused) { p_PauseGame(); }
        }
    }

    public void p_PauseGame()
    {
        //eventSystem.SetSelectedGameObject(resumeButton);

        Time.timeScale = 0;
        isGamePaused = true;

        pauseMenuPanel.SetActive(true);
    }

    public void p_ContinueGame()
    {
        StartCoroutine(ResumeGameCoroutine());
    }

    IEnumerator ResumeGameCoroutine()
    {
        yield return new WaitForSecondsRealtime(0.1f);

        Time.timeScale = 1;
        isGamePaused = false;

        pauseMenuPanel.SetActive(false);
    }

    public void p_RetryGame()
    {
        Time.timeScale = 1;
        isGamePaused = false;

        TransitionManager.instance.ChangeScene(SceneManager.GetActiveScene().buildIndex);
    }

    public void p_MainMenu()
    {
        Time.timeScale = 1;
        isGamePaused = false;

        TransitionManager.instance.ChangeScene("MainMenu");
    }

    public void ButtonSelectSound()
    {
        FMODUnity.RuntimeManager.PlayOneShot("event:/UI/Button_select");
    }
    public void ButtonPressSound()
    {
        FMODUnity.RuntimeManager.PlayOneShot("event:/UI/Button_press");
    }
}