using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class UIManager : MonoBehaviour
{
    [SerializeField]
    TMP_Text timedOutText;

    [SerializeField]
    TMP_Text innocentKillText;

    [SerializeField]
    TMP_Text gameWonText;

    [SerializeField]
    Button RetryButton;

    [SerializeField]
    Button ContinueButton;

    public static UIManager Instance;

    private void Start()
    {
        Instance = this;
        ContinueButton.onClick.AddListener(OnContinue);
        RetryButton.onClick.AddListener(OnRetry);
    }

    private void OnDestroy()
    {
        ContinueButton.onClick.RemoveListener(OnContinue);
        RetryButton.onClick.RemoveListener(OnRetry);
    }

    public void Loose_InnocentKill()
    {
        Invoke(nameof(Loose), 3f);
    }

    void Loose()
    {
        innocentKillText.gameObject.SetActive(true);
        RetryButton.gameObject.SetActive(true);
        PauseManager.Instance.TogglePause(true);
    }

    public void Win()
    {
        Invoke(nameof(Win2), 3f);
    }

    void Win2()
    {
        gameWonText.gameObject.SetActive(true);
        ContinueButton.gameObject.SetActive(true);
        PauseManager.Instance.TogglePause(true);
    }

    public void OnContinue()
    {
        GameManager.Instance.NextScene();
        PauseManager.Instance.Resume();
    }

    public void OnRetry()
    {
        GameManager.Instance.ReloadScene();
        PauseManager.Instance.Resume();
    }
}
