@using System.Windows.Forms
@inherits ButtonBaseComponent<ButtonControl>

<input type="button"
       name="@Control.Name"
       value="@Control.Text"
       style="@GetStyle"
       title="@Control.Text"
       disabled="@IsDisabled"
       @onclick="Click" />

@code {

    private void Click()
    {
        ButtonClick(Control);

        // After
        WebReport.OnUpdate(true);
    }

    private void ButtonClick(ButtonControl button)
    {
        if (button.DialogResult == DialogResult.OK)
        {
            if (FormClose(button, CloseReason.None))
                WebReport.Dialog.CurrentForm++;
        }
        else if (button.DialogResult == DialogResult.Cancel)
        {
            if (FormClose(button, CloseReason.UserClosing))
                WebReport.Canceled = true;
        }
        button.OnClick(null);
    }

    private bool FormClose(ButtonControl button, CloseReason reason)
    {
        DialogPage dialog = button.Report.Pages[WebReport.Dialog.CurrentForm] as DialogPage;
        dialog.Form.DialogResult = button.DialogResult;
        FormClosingEventArgs closingArgs = new FormClosingEventArgs(reason, false);
        dialog.OnFormClosing(closingArgs);
        if (closingArgs.Cancel)
            return false;
        FormClosedEventArgs closedArgs = new FormClosedEventArgs(reason);
        dialog.OnFormClosed(closedArgs);
        dialog.ActiveInWeb = false;
        return true;
    }

    protected override string GetStyle
        => base.GetStyle + $"{GetControlAlign()} padding:0;margin:0;";

}
