using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

public class UIManager : MonoBehaviour
{
    // UI elements
    public TextMeshProUGUI waveText; // Text for displaying current wave number
    public GameObject waveCompleteOverlay; // Overlay for displaying wave complete message
    public GameObject gameOverOverlay; // Overlay for displaying game over message

    /// <summary>
    /// Singleton instance of UIManager.
    /// </summary>
    public static UIManager Instance;

    private void Awake()
    {
        Instance = this; // Assign UIManager instance
    }

    /// <summary>
    /// Displays the current wave number.
    /// </summary>
    public void ShowWaveText()
    {
        // Display current wave number
        waveText.text = $"WAVE {WaveManager.currentWave} INCOMING";

        // Hide the wave number after a delay
        Invoke(nameof(HideWaveText), 3f);
    }

    /// <summary>
    /// Hides the current wave number.
    /// </summary>
    public void HideWaveText()
    {
        waveText.text = string.Empty; // Clear wave number text
    }

    /// <summary>
    /// Shows the game over overlay.
    /// </summary>
    public void ShowGameOver()
    {
        gameOverOverlay.SetActive(true); // Show game over overlay
    }

    /// <summary>
    /// Hides the game over overlay.
    /// </summary>
    public void HideGameOver()
    {
        gameOverOverlay.SetActive(false); // Hide game over overlay
    }

    /// <summary>
    /// Returns to the main menu.
    /// </summary>
    public void ToMenu()
    {
        Loader.fromGame = true; // Set fromGame flag to indicate returning from game
        SceneManager.LoadScene("Loading"); // Load the loading scene to transition to the main menu
    }
}
