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

public class PauseMenu : MonoBehaviour
{
    public static bool IsPaused = false;

    [SerializeField] InputMaster inputAction;    
    [SerializeField] GameObject pauseMenu;

    private void Awake()
    {
        inputAction = new InputMaster();
        inputAction.Menu.Pause.performed += _ => ExecutePauseUnpause();
        
        Debug.Log("In Pause Awake");
    }

    
    private void ExecutePauseUnpause()
    {
        Debug.Log("ExecutePauseUnpause");
        if (IsPaused)
            ResumeGame();
        else
            PauseGame();
    }
    

    private void OnEnable()
    {
        inputAction.Enable();
    }

    private void OnDisable()
    {
        inputAction.Disable();
    }

    void PauseGame()
    {
        Debug.Log("PauseGame");
        Time.timeScale = 0f;
        IsPaused = true;
        pauseMenu.SetActive(true);
    }

    public void ResumeGame()
    {
        Debug.Log("ResumeGame");
        Time.timeScale = 1f;
        IsPaused = false;
        pauseMenu.SetActive(false);
    }

    public void LoadMenu()
    {
        Time.timeScale = 1f;
        Debug.Log("LoadMenu");
        SceneManager.LoadScene(0);
    }

    public void QuitGame()
    {
        Debug.Log("QuitGame");
        Application.Quit();
    }

    
}
