@namespace SufiChain.SufiBlazor.Components.Overlays @using SufiChain.SufiBlazor.Components.Common @using SufiChain.SufiBlazor.Components.Actions @inject IStringLocalizer L @inject IStringLocalizer L @if (_isOpen) {
@if (Icon != null) {
@Icon
} else {
}

@Title

@if (!string.IsNullOrEmpty(Message)) {

@Message

} @if (ChildContent != null) {
@ChildContent
}
@if (ShowCancelButton) { @(CancelText ?? L["Cancel"]) } @(ConfirmText ?? L["Confirm"])
} @code { private bool _isOpen; private TaskCompletionSource? _tcs; /// /// Dialog title. /// [Parameter] public string Title { get; set; } = "Confirm"; /// /// Dialog message. /// [Parameter] public string? Message { get; set; } /// /// Dialog content. /// [Parameter] public RenderFragment? ChildContent { get; set; } /// /// Custom icon. /// [Parameter] public RenderFragment? Icon { get; set; } /// /// Dialog variant. /// [Parameter] public SbConfirmDialogVariant Variant { get; set; } = SbConfirmDialogVariant.Default; /// /// Confirm button text. /// [Parameter] public string? ConfirmText { get; set; } /// /// Cancel button text. /// [Parameter] public string? CancelText { get; set; } /// /// Whether to show cancel button. /// [Parameter] public bool ShowCancelButton { get; set; } = true; /// /// Whether clicking outside closes the dialog. /// [Parameter] public bool CloseOnOverlayClick { get; set; } = true; /// /// Callback when confirmed. /// [Parameter] public EventCallback OnConfirm { get; set; } /// /// Callback when cancelled. /// [Parameter] public EventCallback OnCancel { get; set; } /// /// Additional CSS classes. /// [Parameter] public string? Class { get; set; } private string GetDefaultIconName() => Variant switch { SbConfirmDialogVariant.Danger => "warning", SbConfirmDialogVariant.Warning => "warning", SbConfirmDialogVariant.Info => "info", _ => "help-circle" }; private SbColor GetConfirmButtonColor() => Variant switch { SbConfirmDialogVariant.Danger => SbColor.Danger, SbConfirmDialogVariant.Warning => SbColor.Warning, SbConfirmDialogVariant.Info => SbColor.Info, _ => SbColor.Primary }; /// /// Show the dialog and wait for result. /// public Task ShowAsync() { _tcs = new TaskCompletionSource(); _isOpen = true; StateHasChanged(); return _tcs.Task; } /// /// Show the dialog. /// public void Show() { _isOpen = true; StateHasChanged(); } /// /// Close the dialog. /// public void Close() { _isOpen = false; StateHasChanged(); } private async Task Confirm() { _isOpen = false; _tcs?.TrySetResult(true); await OnConfirm.InvokeAsync(); } private async Task Cancel() { _isOpen = false; _tcs?.TrySetResult(false); await OnCancel.InvokeAsync(); } private async Task OnOverlayClick() { if (CloseOnOverlayClick) { await Cancel(); } } }