using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
    public static bool GameIsPaused = false;
    public GameObject PauseMenuUI;
    public GameManager gameManager;
    public GameObject ResumeButton;
    private bool isLoading = true;
    
    
    void Update()
    {
        if(isLoading == false)
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (GameIsPaused)
                {
                    Resume();
                }
                else
                {
                    Pause();
                }
            }
        
        }
    }

    public void MainMenu()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
    }
    
    public void QuitGame()
    {
        Debug.Log("Quit Game");
        Application.Quit();
    }
    public void Resume()
    {
        PauseMenuUI.SetActive(false);
        Time.timeScale = 1;
        GameIsPaused = false;
        EventSystem.current.SetSelectedGameObject(null);
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }

    void Pause()
    {
        PauseMenuUI.SetActive(true);
        Time.timeScale = 0;
        GameIsPaused = true;
        EventSystem.current.SetSelectedGameObject(null);
        EventSystem.current.SetSelectedGameObject(ResumeButton);
        Cursor.lockState = CursorLockMode.None;
        Cursor.visible = true;
    }
    
    public void SaveGame()
    {
        Debug.Log("Save Game");
        SaveSystem.SaveGame(gameManager);
    }



    public void LoadGame()
    {
        Debug.Log("Load Game");
        GameData data = SaveSystem.LoadGame();

    }

    public void SetIsLoading(bool isLoading)
    {
        this.isLoading = isLoading;
    }
}
