@namespace OpenArchival.Blazor
@using MudBlazor

<Microsoft.AspNetCore.Components.Forms.EditForm Model="this" OnSubmit="OnSubmit">
<MudTextField FullWidth="true"
              AutoFocus="string.IsNullOrEmpty(SearchTerms)"
              Placeholder="Search"
              T="string"
              Variant="Variant.Outlined"
              Adornment="Adornment.Start"
              AdornmentIcon="@Icons.Material.Filled.Search"
              Class="mt-5"
              @bind-Value="SearchTerms"
               />

<MudExpansionPanel Text="Filter...">
    <MudText Typo="Typo.caption">Choose which data the serach bar will search on:</MudText>
    <MudDivider></MudDivider>

    <MudRadioGroup T="@BlogSearchFilterType" @bind-SelectedOption="SelectedFilter">
        <MudRadio Option="BlogSearchFilterType.All" T="BlogSearchFilterType">All</MudRadio>
        <MudRadio Option="BlogSearchFilterType.Title" T="BlogSearchFilterType">Title</MudRadio>
        <MudRadio Option="BlogSearchFilterType.Content" T="BlogSearchFilterType">Content</MudRadio>
        <MudRadio Option="BlogSearchFilterType.Tags" T="BlogSearchFilterType">Tags</MudRadio>
    </MudRadioGroup>
</MudExpansionPanel>
</Microsoft.AspNetCore.Components.Forms.EditForm>
@code {
    [Parameter]
    public string SearchTerms { get; set; } = "";

    [Parameter]
    public EventCallback<string> SearchTermsChanged { get; set; }

    [Parameter]
    public BlogSearchFilterType SelectedFilter { get; set; } = BlogSearchFilterType.All;

    [Parameter]
    public EventCallback<BlogSearchFilterType> SelectedFilterChanged { get; set; }

    private async Task HandleSearchKeyDown(Microsoft.AspNetCore.Components.Web.KeyboardEventArgs args)
    {
        if (args.Key == "Enter")
        {
            await SearchTermsChanged.InvokeAsync(SearchTerms);
        }
    }
    private async Task OnSubmit(Microsoft.AspNetCore.Components.Forms.EditContext args)
    {
        await SearchTermsChanged.InvokeAsync(SearchTerms);
    }
}