using Codex.Events.Channels;
using UnityEngine;

public class UiManager : MonoBehaviour
{
    [SerializeField] private GameObject gameOverPanel;
    [SerializeField] private VoidEventChannelSO onRestart;
    [SerializeField] private VoidEventChannelSO onGameOver;
    
    private void Start()
    {
        HideGameOver();
    }
    
    private void OnEnable()
    {
        onGameOver.OnEventRaised += ShowGameOver;
    }
    
    private void OnDisable()
    {
        onGameOver.OnEventRaised -= ShowGameOver;
    }
    
    private void ShowGameOver()
    {
        gameOverPanel.SetActive(true);
    }
    
    private void HideGameOver()
    {
        gameOverPanel.SetActive(false);
    }
    
    public void OnRestartPressed()
    {
        Restart();
    }
    
    private void Restart()
    {
        HideGameOver();
        onRestart.RaiseEvent();
    }
}
