using Godot;
using Newlon.Components.Zombies;

namespace Newlon.Components.Level;

public partial class LoseCheckbox : Area2D
{
	[Export] private CanvasLayer gameOverLayer;
	[Export] private AnimationPlayer fadeAnimation;
	public override void _Ready()
	{
		AreaEntered += OnAreaEntered;
	}

	private void OnAreaEntered(Area2D area)
	{
		var parent = area.GetParent();
		if (parent != null && parent is RuntimeZombieData zombieData)
		{
			Engine.TimeScale = 1.0;
			fadeAnimation.Play("fade");
			GetTree().Paused = true;
			PhysicsServer2D.SetActive(true);
			Callable.From(()=>
			{
				zombieData.Reparent(gameOverLayer);
			}).CallDeferred();
			
		}
	}
}
