using Game.Extensions;
using Godot;

namespace Game;

public partial class DropZone : Control
{
    public override bool _CanDropData(Vector2 atPosition, Variant data)
    {
        return data.VariantType == Variant.Type.Object
            && data.AsGodotObject() is MeetingControlDragData;
    }

    public override void _DropData(Vector2 atPosition, Variant data)
    {
        var meetingControl = ((MeetingControlDragData)data).MeetingControl;
        var meetingPhysicsBox = meetingControl.MeetingPhysicsBox;

        var game = NodeExtensions.GetMain(this);
        game.AddChild(meetingPhysicsBox);
        meetingPhysicsBox.Position = GetGlobalMousePosition();
        meetingControl.QueueFree();

        meetingControl.DragIsHandled = true;
    }

    public override void _Notification(int what)
    {
        if (what == NotificationDragBegin)
            MouseFilter = MouseFilterEnum.Pass;

        if (what == NotificationDragEnd)
            MouseFilter = MouseFilterEnum.Ignore;
    }
}
