using Blazorise;
using Microsoft.AspNetCore.Components;
using ProjetBlazor.Models;

namespace ProjetBlazor.Components
{
    public partial class GetItemInInventory
    {
        [Parameter]
        public int Index { get; set; }

        [Parameter]
        public Item? Item { get; set; }

        [Parameter]
        public bool NoDrop { get; set; }

        [CascadingParameter]
        public ItemsList Parent { get; set; }

        internal void OnDragEnter()
        {
            if (NoDrop)
            {
                return;
            }

            Parent.Actions.Add(new ItemInInventory { Item = this.Item, Index = this.Index });
        }

        internal void OnDragLeave()
        {
            if (NoDrop)
            {
                return;
            }

            Parent.Actions.Add(new ItemInInventory { Item = this.Item, Index = this.Index });
        }

        internal void OnDrop()
        {
            if (NoDrop)
            {
                return;
            }

            this.Item = Parent.CurrentDragItem;

            Parent.Actions.Add(new ItemInInventory { Item = this.Item, Index = this.Index });

            // Check recipe
        }

        private void OnDragStart()
        {
            Parent.CurrentDragItem = this.Item;

            Parent.Actions.Add(new ItemInInventory { Item = this.Item, Index = this.Index });
        }
    }
}
