@namespace Lumeo
@inject Lumeo.Services.Localization.ILumeoLocalizer L

<button type="button" class="@CssClass" @onclick="Toggle" aria-label="@L["Navigation.Toggle"]" @attributes="AdditionalAttributes">
    <Blazicon Svg="Lucide.Menu" class="h-5 w-5" />
</button>

@code {
    [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; }

    [Parameter] public string? Class { get; set; }
    [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }

    private string CssClass => $"inline-flex items-center justify-center rounded-md p-2 hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-[1.5px] focus-visible:ring-ring focus-visible:ring-offset-2 md:hidden {Class}".Trim();

    private async Task Toggle()
    {
        Open = !Open;
        await OpenChanged.InvokeAsync(Open);
    }
}
