using Telerik.WinControls.UI;

namespace Pilz.UI.Telerik.Dialogs;

public partial class RadDialogBase : RadForm
{
    public RadFlyoutBase? DialogPanel { get; private set; }

    private RadDialogBase()
    {
        Load += DialogBaseForm_Load;
        FormClosed += DialogBaseForm_FormClosed;
    }

    public RadDialogBase(RadFlyoutBase dialogPanel) : this()
    {
        DialogPanel = dialogPanel;
    }

    private void DialogBaseForm_Load(object? sender, EventArgs e)
    {
        if (DialogPanel is ILoadContent iLoadContent)
            iLoadContent.LoadContent();
        else if (DialogPanel is ILoadContentAsync iLoadContentAsync)
            Task.Run(iLoadContentAsync.LoadContentAsync).Wait();

        DialogLoading?.Invoke(new DialogLoadingEventArgs(this));
    }

    private void DialogBaseForm_FormClosed(object? sender, FormClosedEventArgs e)
    {
        DialogClosed?.Invoke(new DialogClosedEventArgs(this));
    }
}
