@using JSMR.Application.VoiceWorks.Queries.Search
@using JSMR.UI.Blazor.Filters
@using Microsoft.AspNetCore.WebUtilities

<a class="j-tag" @onclick="@OnClick">@Tag.Name</a>
@* <MudChip T="string" Icon="@Icons.Material.Outlined.Tag" @onclick="@OnClick" Variant="@MudBlazor.Variant.Filled" Color="@MudBlazor.Color.Surface">@Tag.Name</MudChip> *@

@code {
    [Inject]
    protected NavigationManager NavigationManager { get; set; } = default!;

    [Parameter]
    public required VoiceWorkTagItem Tag { get; set; }

    private void OnClick()
    {
        VoiceWorkFilterState state = new()
        {
            TagIds = [Tag.TagId]
        };

        //string basePath = new Uri(NavigationManager.Uri).GetLeftPart(UriPartial.Path);
        string basePath = new Uri(NavigationManager.Uri).GetLeftPart(UriPartial.Authority);
        string uri = QueryHelpers.AddQueryString($"{basePath}/voiceworks", state.ToQuery());

        NavigationManager.NavigateTo(uri);
    }
}