namespace InABox.Core
{
    public delegate void EditorButtonClick(object editor, object? item);
    public delegate void EditorButtonClick<T>(object editor, T? item) where T : class;
    public delegate void EditorButtonEnabled(bool enabled);
    public delegate void EditorButtonVisible(bool visible);

    public class EditorButton
    {
        public EditorButton(object? item, string caption, int width, EditorButtonClick onclick, bool disableeditor)
        {
            Width = width;
            Caption = caption;
            OnClick = onclick;
            Item = item;
            DisableEditor = disableeditor;
            IsEnabled = true;
            IsVisible = true;
        }

        public int Width { get; }

        public string Caption { get; }

        public object? Item { get; }

        public bool DisableEditor { get; }

        public bool IsEnabled { get; private set; }

        public bool IsVisible { get; private set; }


        public event EditorButtonClick OnClick;
        public event EditorButtonEnabled OnEnabled;
        public event EditorButtonEnabled OnVisible;

        public void Click(object editor)
        {
            if (IsEnabled)
            {
                OnClick?.Invoke(editor, Item);
            }
        }

        public void SetEnabled(bool enabled)
        {
            IsEnabled = enabled;
            OnEnabled?.Invoke(enabled);
        }

        public void SetVisible(bool visible)
        {
            IsVisible = visible;
            OnVisible?.Invoke(visible);
        }
    }
}