@using JSMR.Application.Circles.Queries.Search
@using JSMR.UI.Blazor.Enums
@using JSMR.UI.Blazor.Filters
@using JSMR.UI.Blazor.Services

<div class="search-filter-control-container">
    <div class="search-filter-control-span-3">
        <BitTextField Placeholder="Circle Name or Maker Id"
                      Immediate="true"
                      DebounceTime="500"
                      Value="@Value.Keywords"
                      ValueChanged="@(value => Update(Value with { Keywords = value }))">
            <PrefixTemplate>
                <InputPrefix Graphic="Graphic.Search" Tooltip="Search"></InputPrefix>
            </PrefixTemplate>
        </BitTextField>
    </div>
    <div class="search-filter-control-span-1">
        <BitDropdown Items="CircleStatuses"
                     Placeholder="Select..."
                     TItem="BitDropdownItem<CircleStatus?>"
                     TValue="CircleStatus ?"
                     Value="@Value.Status"
                     ValueChanged="@(value => Update(Value with { Status = value }))">
            <PrefixTemplate>
                <InputPrefix Graphic="Graphic.Circle" Tooltip="Circles"></InputPrefix>
            </PrefixTemplate>
        </BitDropdown>
    </div>
</div>

@code {
    [Parameter]
    public CircleFilterState Value { get; set; } = new();

    [Parameter]
    public EventCallback<CircleFilterState> ValueChanged { get; set; }

    List<BitDropdownItem<CircleStatus?>> CircleStatuses =
    [
        new() { Text = "Not Blacklisted", Value = CircleStatus.NotBlacklisted },
        new() { Text = "Favorites",       Value = CircleStatus.Favorited      },
        new() { Text = "Blacklisted",     Value = CircleStatus.Blacklisted    },
        new() { Text = "Spam",            Value = CircleStatus.Spam           },
        new() { Text = "All",             Value = null                        }
    ];

    private Task Update(CircleFilterState next)
        => ValueChanged.InvokeAsync(next with { PageNumber = 1 });
}
