using UnityEngine;
using UnityEngine.InputSystem;

public class Pause : MonoBehaviour
{
    public SpriteRenderer pauseBacgkround;

    public SpriteRenderer pauseLabel;

    public AudioClip pauseSound;

    public MusicManager musicManager;

    private bool isPaused = false;

    private AudioSource audioSource;

    private static Color colorBlackTransparent = new Color(0.0f, 0.0f, 0.0f, 0.0f);
    private static Color colorBlackOpaque = new Color(0.0f, 0.0f, 0.0f, 1.0f);
    private static Color colorWhiteTransparent = new Color(1.0f, 1.0f, 1.0f, 0.0f);
    private static Color colorWhiteOpaque = new Color(1.0f, 1.0f, 1.0f, 1.0f);

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        audioSource = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Keyboard.current != null && Keyboard.current.capsLockKey.wasPressedThisFrame)
        {
            isPaused = !isPaused;
            pauseBacgkround.color = isPaused ? colorBlackOpaque : colorBlackTransparent;
            pauseLabel.color = isPaused ? colorWhiteOpaque : colorWhiteTransparent;

            if (isPaused)
            {
                audioSource.PlayOneShot(pauseSound);
                musicManager.PauseMusic();
                Time.timeScale = 0.0f; // Pause the game
            } 
            else
            {
                musicManager.ResumeMusic();
                Time.timeScale = 1.0f; // Resume the game
            }
        }
    }
}
