@inject IJSRuntime jsRuntime;
@inject IImmortalSelectionService filterService

<FormLayoutComponent>
    <FormSelectComponent OnChange="@OnFactionChanged">
        <FormLabelComponent>Faction</FormLabelComponent>
        <ChildContent>
            <option value="@FactionType.Aru">Aru</option>
            <option value="@FactionType.QRath" selected>Q'Rath</option>
        </ChildContent>
    </FormSelectComponent>

    <FormSelectComponent OnChange="@OnImmortalChanged">
        <FormLabelComponent>Immortal</FormLabelComponent>
        <ChildContent>
            @if (filterService.GetFactionType() == FactionType.QRath)
            {
                <option value="@DataType.IMMORTAL_Orzum" selected>Orzum</option>
                <option value="@DataType.IMMORTAL_Ajari">Ajari</option>
            }
            @if (filterService.GetFactionType() == FactionType.Aru)
            {
                <option value="@DataType.IMMORTAL_Mala" selected>Mala</option>
                <option value="@DataType.IMMORTAL_Xol">Xol</option>
            }
        </ChildContent>
    </FormSelectComponent>
</FormLayoutComponent>

@code {

    void OnFactionChanged(ChangeEventArgs e)
    {
        filterService.SelectFactionType(e.Value!.ToString()!);
    }

    void OnImmortalChanged(ChangeEventArgs e)
    {
        filterService.SelectImmortalType(e.Value!.ToString()!);
    }

    protected override bool ShouldRender()
    {
#if DEBUG
        jsRuntime.InvokeVoidAsync("console.time", "FilterComponent");
#endif

        return true;
    }

    protected override void OnAfterRender(bool firstRender)
    {
#if DEBUG
        jsRuntime.InvokeVoidAsync("console.timeEnd", "FilterComponent");
#endif
    }

}