using UnityEngine;
using UnityEngine.EventSystems;

public class UIToolbar : MonoBehaviour, IDropHandler
{
    public ElementType ElementMask;
    public LayoutMode Layout;

    [System.Flags]
    public enum ElementType
    {
        None = 0,
        Toolbar = 1,
        Dynamic = 2
    }

    public enum LayoutMode
    {
        Horizontal,
        Vertical
    }

    public void OnDrop(PointerEventData eventData)
    {
        if (eventData.pointerDrag.TryGetComponent<UIElementDragger>(out var draggable))
        {
            if (!ElementMask.HasFlag(draggable.ElementType) || draggable.LockProxyState || draggable.LastDragAction != UIElementDragger.DragAction.Position) return;
            AttachToThis(draggable);
        }
    }

    public void AttachToThis(UIElementDragger draggable)
    {
        var proxy = UIDraggableProxy.Create(transform).Link(draggable);
        draggable.gameObject.SetActive(false);
    }

    private void OnDisable()
    {
        foreach(var proxy in GetComponentsInChildren<UIDraggableProxy>())
        {
            proxy.SetDraggableVisible(false);
        }
    }
}
