@using MudBlazor

<MudDialog>
    <TitleContent>
        <div class="pa-4" style="background-color: #f44336; margin: -16px -24px 0 -24px;">
            <div class="d-flex align-center justify-center">
                <MudIcon Icon="@Icons.Material.Filled.Warning" Style="color: white;" Size="Size.Large" />
                <MudText Typo="Typo.h6" Style="color: white; font-weight: 800; margin-left: 12px;">Confirm Delete</MudText>
            </div>
        </div>
    </TitleContent>
    <DialogContent>
        <div class="pa-4 text-center">
            <MudText Typo="Typo.body1" Class="mb-2">Are you sure you want to delete <b>@ContentText</b>?</MudText>
            <MudText Typo="Typo.body2" Color="Color.Error" Style="font-weight: 700;">This action cannot be undone.</MudText>
        </div>
    </DialogContent>
    <DialogActions>
        <div class="d-flex justify-center gap-2 w-100 pb-4">
            <MudButton OnClick="Cancel"
                       Variant="Variant.Outlined"
                       Disabled="_isDeleting"
                       Style="border-radius: 4px; border: 1px solid #e0e0e0; text-transform: none; font-weight: 700;">Cancel</MudButton>
            <MudButton Color="Color.Error"
                       Variant="Variant.Filled"
                       OnClick="HandleSubmit"
                       Disabled="_isDeleting"
                       Style="border-radius: 4px; text-transform: none; font-weight: 700;">
                @if (_isDeleting)
                {
                    <MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
                    <MudText Class="ms-2" Typo="Typo.button" Style="text-transform: none !important;">Deleting...</MudText>
                }
                else
                {
                    <MudText>Yes, Delete It</MudText>
                }
            </MudButton>
        </div>
    </DialogActions>
</MudDialog>

@code {
    [CascadingParameter] IMudDialogInstance MudDialog { get; set; } = default!;
    [Parameter] public string ContentText { get; set; } = string.Empty;

    private bool _isDeleting = false;

    private async Task HandleSubmit()
    {
        _isDeleting = true;
        StateHasChanged();
        await Task.Delay(1000);
        MudDialog.Close(DialogResult.Ok(true));
    }

    private void Cancel() => MudDialog.Cancel();
}