@namespace Lumeo

<button data-slot="scrollspy-link"
        data-active="@(Context?.ActiveId == Target ? "true" : null)"
        class="@CssClass"
        @onclick="HandleClick"
        @attributes="AdditionalAttributes">
    @ChildContent
</button>

@code {
    [CascadingParameter] public Scrollspy.ScrollspyContext? Context { get; set; }
    [Parameter, EditorRequired] public string Target { get; set; } = "";
    [Parameter] public RenderFragment? ChildContent { get; set; }
    [Parameter] public string? Class { get; set; }
    [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }

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

    private async Task HandleClick()
    {
        if (Context is not null)
        {
            await Context.OnNavigate.InvokeAsync(Target);
        }
    }
}
