@namespace Lumeo

@{
    var context = new SheetContext(Open, EventCallback.Factory.Create<bool>(this, SetOpen), _titleId, _descriptionId);
}

<CascadingValue Value="context" IsFixed="false">
    @ChildContent
</CascadingValue>

@code {
    [Parameter] public RenderFragment? ChildContent { get; set; }
    [Parameter] public bool Open { get; set; }
    [Parameter] public EventCallback<bool> OpenChanged { get; set; }

    [Obsolete("Use Open instead. IsOpen will be removed in a future release.")]
    [Parameter] public bool IsOpen { get => Open; set => Open = value; }

    [Obsolete("Use OpenChanged instead. IsOpenChanged will be removed in a future release.")]
    [Parameter] public EventCallback<bool> IsOpenChanged { get => OpenChanged; set => OpenChanged = value; }

    private readonly string _titleId = $"sheet-title-{Guid.NewGuid():N}";
    private readonly string _descriptionId = $"sheet-desc-{Guid.NewGuid():N}";

    private async Task SetOpen(bool value)
    {
        Open = value;
        await OpenChanged.InvokeAsync(value);
    }

    public record SheetContext(bool IsOpen, EventCallback<bool> SetOpen, string TitleId, string DescriptionId);
}
