@inject DialogService DialogService

<div class="rz-p-12 rz-text-align-center">
    <RadzenButton Text="Busy Dialog with a string message" ButtonStyle="ButtonStyle.Secondary" Click=@(args => ShowBusyDialog(true)) />
    <RadzenButton Text="Busy Dialog with markup" ButtonStyle="ButtonStyle.Secondary" Click=@(args => ShowBusyDialog(false)) />
</div>

@code {
    async Task ShowBusyDialog(bool withMessageAsString)
    {
        _ = InvokeAsync(async () =>
        {
            // Simulate background task
            await Task.Delay(2000);

            // Close the dialog
            DialogService.Close();
        });

        if (withMessageAsString)
        {
            await BusyDialog("Busy ...");
        }
        else
        {
            await BusyDialog();
        }
    }

    // Busy dialog from markup
    async Task BusyDialog()
    {
        await DialogService.OpenAsync("", ds =>
    @<RadzenStack AlignItems="AlignItems.Center" Gap="2rem" class="rz-p-12">
        <RadzenImage Path="images/community.svg" Style="width: 200px;" AlternateText="community" />
        <RadzenText TextStyle="TextStyle.H6">Loading, please wait...</RadzenText>
    </RadzenStack>, new DialogOptions() { ShowTitle = false, Style = "min-height:auto;min-width:auto;width:auto", CloseDialogOnEsc = false });
    }

    // Busy dialog from string
    async Task BusyDialog(string message)
    {
        await DialogService.OpenAsync("", ds =>
        {
            RenderFragment content = dialogContent =>
            {
                dialogContent.OpenComponent<RadzenRow>(0);
                dialogContent.AddComponentParameter(1, nameof(RadzenRow.ChildContent), (RenderFragment)(rowContent => 
                {
                    rowContent.OpenComponent<RadzenColumn>(0);
                    rowContent.AddComponentParameter(1, nameof(RadzenColumn.Size), 12);
                    rowContent.AddComponentParameter(2, nameof(RadzenRow.ChildContent), (RenderFragment)(columnContent => 
                    {
                        columnContent.AddContent(0, message);
                    }));
                    rowContent.CloseComponent();
                }));

                dialogContent.CloseComponent();
            };
            return content;
        }, new DialogOptions() { ShowTitle = false, Style = "min-height:auto;min-width:auto;width:auto", CloseDialogOnEsc = false });
    }
}