namespace ScadaLink.CentralUI.Components.Shared;
///
/// Default implementation. Holds the currently
/// open dialog state in and notifies subscribers (the
/// DialogHost component) via . Only a single
/// dialog can be open at a time; attempting to open another while one is
/// already active throws — there is
/// no nested-dialog use case today and surfacing the bug is preferable to
/// silently queuing.
///
public class DialogService : IDialogService
{
///
/// Raised whenever changes (dialog opened or closed).
/// The host component subscribes and calls StateHasChanged.
///
public event Action? OnChange;
///
/// The dialog currently being displayed, or null when no dialog is
/// open. The host reads this to decide what (if anything) to render.
///
public DialogState? Current { get; private set; }
// CentralUI-015: the pending dialog result is held in a typed TCS that the
// host completes directly via Resolve(). The previous implementation
// projected the result through Task.ContinueWith(..., TaskScheduler.Default),
// which ran the projection lambda on a thread-pool thread. Completing a
// strongly-typed TCS directly removes that off-render-thread hop entirely —
// the awaiting caller resumes on whatever SynchronizationContext it captured
// (the Blazor renderer's, for an event-handler caller).
private TaskCompletionSource