using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using static InABox.DynamicGrid.DynamicEditorButton;

namespace InABox.DynamicGrid
{
    public class DynamicEditorButton
    {
        public delegate void ClickHandler(object sender, object? item);
        public delegate void ClickHandler<T>(object sender, T item);

        public DynamicEditorButton(string name, BitmapImage? image, object? item, ClickHandler onclick)
        {
            Name = name;
            OnClick = onclick;
            Item = item;
            Image = image;
        }

        public string Name { get; set; }

        public object? Item { get; set; }

        public BitmapImage? Image { get; set; }

        public Button Button { get; set; }
        public object Form { get; set; }
        public event ClickHandler OnClick;

        public void Click()
        {
            OnClick?.Invoke(Form, Item);
        }
    }

    public class DynamicEditorButtons : List<DynamicEditorButton>
    {
        public DynamicEditorButton Add(string name, BitmapImage? image, object? item, ClickHandler onclick)
        {
            var editorbutton = new DynamicEditorButton(name, image, item, onclick);
            Add(editorbutton);
            return editorbutton;
        }

        public DynamicEditorButton Add<T>(string name, BitmapImage? image, T item, ClickHandler<T> onClick)
        {
            var editorbutton = new DynamicEditorButton(name, image, item, (o, e) => onClick(o, (T)e));
            Add(editorbutton);
            return editorbutton;
        }
    }
}