@inject IJSRuntime JsRuntime;
@inject IImmortalSelectionService FilterService

<FormLayoutComponent>
    <FormSelectComponent OnChange="@OnFactionChanged">
        <FormLabelComponent>Faction</FormLabelComponent>
        <ChildContent>
            <option value="@DataType.FACTION_Aru"
                    selected="@(FilterService.GetFaction().Equals(DataType.FACTION_Aru))">
                Aru
            </option>
            <option value="@DataType.FACTION_QRath"
                    selected="@(FilterService.GetFaction().Equals(DataType.FACTION_QRath))">
                Q'Rath
            </option>
        </ChildContent>
    </FormSelectComponent>

    <FormSelectComponent OnChange="@OnImmortalChanged">
        <FormLabelComponent>Immortal</FormLabelComponent>
        <ChildContent>
            @if (FilterService.GetFaction() == DataType.FACTION_QRath)
            {
                <option value="@DataType.IMMORTAL_Orzum"
                        selected="@(FilterService.GetImmortal().Equals(DataType.IMMORTAL_Orzum))">
                    Orzum
                </option>
                <option value="@DataType.IMMORTAL_Ajari"
                        selected="@(FilterService.GetImmortal().Equals(DataType.IMMORTAL_Ajari))">
                    Ajari
                </option>
            }
            @if (FilterService.GetFaction() == DataType.FACTION_Aru)
            {
                <option value="@DataType.IMMORTAL_Atzlan"
                        selected="@(FilterService.GetImmortal().Equals(DataType.IMMORTAL_Atzlan))">
                    Atzlan
                </option>
                <option value="@DataType.IMMORTAL_Mala"
                        selected="@(FilterService.GetImmortal().Equals(DataType.IMMORTAL_Mala))">
                    Mala
                </option>
                <option value="@DataType.IMMORTAL_Xol"
                        selected="@(FilterService.GetImmortal().Equals(DataType.IMMORTAL_Xol))">
                    Xol
                </option>
            }
        </ChildContent>
    </FormSelectComponent>
</FormLayoutComponent>

@code {

    void OnFactionChanged(ChangeEventArgs e)
    {
        FilterService.SelectFaction(e.Value!.ToString()!);
    }

    void OnImmortalChanged(ChangeEventArgs e)
    {
        FilterService.SelectImmortal(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
    }

}