using Pilz.UI.Telerik;
using Pilz.UI.Telerik.Dialogs;
using System.Drawing;
using System.Windows.Forms;
using Telerik.WinControls;

namespace Pilz.Plugins.Advanced
{
    public abstract class PluginModule : PluginFeature
    {
        public delegate void PluginModuleUIEventHandler(PluginModule module, PluginModuleUI ui);

        /// <summary>
        /// Fires when a <see cref="PluginModuleUI"/> instance has been created.
        /// </summary>
        public static event PluginModuleUIEventHandler? OnUICreated;

        public bool Visible { get; set; } = true;
        public bool AllowEmbedding { get; set; } = true;

        protected PluginModule(string moduleType, string moduleName) : base(moduleType, moduleName)
        {
        }

        public virtual void ShowUI()
        {
            if (CreateNewUI() is PluginModuleUI ui)
            {
                ui.BackColor = Color.Transparent;
                DialogBaseForm.Show(ui, Name!, Icon!.ToImage().ToIcon()!);
            }
        }

        public virtual PluginModuleUI CreateUI()
        {
            var ui = CreateNewUI();
            OnUICreated?.Invoke(this, ui);
            return ui;
        }

        protected abstract PluginModuleUI CreateNewUI();
    }
}