@namespace Lumeo

@{
    var menuContext = new MenubarMenuContext(_menuId, _wrapperId);
}

<CascadingValue Value="menuContext" IsFixed="true">
    <div id="@_wrapperId" class="@CssClass" @attributes="AdditionalAttributes">
        @ChildContent
    </div>
</CascadingValue>

@code {
    [CascadingParameter] public Menubar.MenubarContext Context { get; set; } = default!;
    [Parameter] public RenderFragment? ChildContent { get; set; }
    [Parameter] public string? Class { get; set; }
    [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }

    private readonly string _menuId = Guid.NewGuid().ToString("N");
    private readonly string _wrapperId = $"menubar-menu-{Guid.NewGuid():N}";

    private string CssClass => $"relative {Class}".Trim();

    protected override void OnInitialized()
    {
        Context.RegisterMenuId(_menuId);
    }

    public record MenubarMenuContext(string MenuId, string WrapperId);
}
