using Blazorise; using FoodsharingSiegen.Server.BaseClasses; using Microsoft.AspNetCore.Components; namespace FoodsharingSiegen.Server.Dialogs { public partial class ConfirmDialog : FsBase { #region Parameters [Parameter] public Func? OnConfirm { get; set; } [Parameter] public string? Message { get; set; } #endregion #region Public Method ShowAsync /// /// Displays the confirm dialog with the specified title, message, and confirmation action. /// /// The modal service used to display the dialog. /// The title of the confirmation dialog. Defaults to "Bestätigen" if null. /// The message displayed in the confirmation dialog. /// The action to invoke when the user confirms. /// A task that represents the asynchronous operation of displaying the dialog. public static async Task ShowAsync(IModalService modalService, string? title, string? message, Func onConfirm) { title ??= "Bestätigen"; var x = new Action>(b => { b.Add(nameof(OnConfirm), onConfirm); b.Add(nameof(Message), message); }); var options = new ModalInstanceOptions { Size = ModalSize.Small }; await modalService.Show(title, x, options); } #endregion #region Private Method ConfirmClickAsync /// /// Invokes the confirmation action if it is set. /// /// A task that represents the asynchronous operation. private async Task ConfirmClickAsync() { if (OnConfirm != null) await OnConfirm.Invoke(); await ModalService.Hide(); } #endregion } }