using Godot;
using Godot.Collections;

public partial class GameOverService : Control
{
   [Signal]
   public delegate void ReloadGameEventHandler();

   private GameManager _gameManager;

   public override void _EnterTree()
   {
      _gameManager = GetTree().Root.GetNode<GameManager>("Main/GameManager");
   }

   public void OnGameOver(Array<Player> players)
   {
      Show();
      var bgmPlayer = GetTree().Root.GetNode<BGMPlayer>("BgmPlayer");
      bgmPlayer.SetBGMFromFilepath("Audio/BGM/GameOverTheme.ogg");
      bgmPlayer.PlayBGM();
      foreach (var player in players)
      {
         if (Input.IsActionJustPressed(player.PlayerInput.Fire()))
         {
            Hide(); 
            _gameManager.IsGameOverScreenOn = false;
            EmitSignal(SignalName.ReloadGame);
         }
      }
   }
}
