using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace AntDesign { /// /// /// public class ConfirmRef { #region internal internal IModalTemplate ModalTemplate { get; set; } internal bool IsCreateByModalService => Service != null; internal TaskCompletionSource TaskCompletionSource { get; set; } internal ConfirmRef(ConfirmOptions config) { Config = config; } internal ConfirmRef(ConfirmOptions config, ModalService service) { Config = config; Service = service; } internal Confirm Confirm { get; set; } #endregion /// /// /// protected ModalService Service { get; set; } /// /// Confirm dialog options /// public ConfirmOptions Config { get; private set; } /// /// on Confirm open /// public Func OnOpen { get; set; } /// /// on Confirm close /// public Func OnClose { get; set; } /// /// open Confirm dialog /// /// public async Task OpenAsync() { await (Service?.OpenConfirmAsync(this) ?? Task.CompletedTask); } /// /// close Confirm dialog /// /// public async Task CloseAsync() { await (Service?.DestroyConfirmAsync(this) ?? Task.CompletedTask); } /// /// update Confirm dialog config which Visible=true /// /// public async Task UpdateConfigAsync() { await (Service?.UpdateConfirmAsync(this) ?? Task.CompletedTask); } /// /// update Confirm dialog config with a new ConfirmOptions /// /// /// public async Task UpdateConfigAsync(ConfirmOptions config) { Config = config; await UpdateConfigAsync(); } } /// /// ConfirmRef for /// /// public class ConfirmRef : ConfirmRef { /// /// on Cancel button click /// public Func OnCancel { get; set; } /// /// on OK button click /// public Func OnOk { get; set; } internal ConfirmRef(ConfirmOptions config, ModalService service) : base(config, service) { } /// /// Trigger OK button /// /// public async Task TriggerOkAsync(TResult result) { await base.CloseAsync(); await (OnOk?.Invoke(result) ?? Task.CompletedTask); } /// /// Trigger cancel button /// /// public async Task TriggerCancelAsync(TResult result) { await base.CloseAsync(); await (OnCancel?.Invoke(result) ?? Task.CompletedTask); } } }