<div class="desktopFilters">
    <div class="desktopFiltersContainer">
        <div class="filtersContainer">
            <div class="filterContainer">
                @foreach (var choice in EntityFilterService.GetFactionChoices())
                {
                    var styleClass = "";
                    if (choice.Equals(EntityFilterService.GetFactionType()))
                    {
                        styleClass = "selected";
                    }
                    <button @onclick="@(e => OnChangeFaction(choice))" class="choiceButton @styleClass">@choice</button>
                }
            </div>

            @if (EntityFilterService.GetFactionType() != "Any" && EntityFilterService.GetFactionType() != "None")
            {
                <div class="filterContainer">
                    @foreach (var choice in EntityFilterService.GetImmortalChoices())
                    {
                        var name = DATA.Get()[choice].Info().Name;

                        var styleClass = "";
                        if (choice.Equals(EntityFilterService.GetImmortalType()))
                        {
                            styleClass = "selected";
                        }
                        <button class="choiceButton @styleClass" @onclick="@(e => OnChangeImmortal(choice))">@name</button>
                    }
                </div>
            }
        </div>
        <div class="filterContainer">
            @foreach (var choice in EntityFilterService.GetEntityChoices())
            {
                var styleClass = "";
                if (choice.Equals(EntityFilterService.GetEntityType()))
                {
                    styleClass = "selected";
                }

                <button class="choiceButton @styleClass" @onclick="@(e => OnChangeEntity(choice))">@choice.Replace("_", " ")</button>
            }
        </div>
        <FormTextComponent Label="Search Label" Placeholder="Throne..." OnChange="@(e => EntityFilterService.EnterSearchText(e.Value!.ToString()!))"/>
    </div>
</div>

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

        <FormSelectComponent OnChange="@OnImmortalChanged">
            <FormLabelComponent>Immortal</FormLabelComponent>
            <ChildContent>
                <option value="@ImmortalType.Any" selected>Any</option>
                <option value="@DataType.IMMORTAL_Mala">Mala</option>
                <option value="@DataType.IMMORTAL_Xol">Xol</option>
                <option value="@DataType.IMMORTAL_Orzum">Orzum</option>
                <option value="@DataType.IMMORTAL_Ajari">Ajari</option>
            </ChildContent>
        </FormSelectComponent>

        <FormSelectComponent OnChange="@OnEntityChanged">
            <FormLabelComponent>Entity</FormLabelComponent>
            <ChildContent>
                <option value="@EntityType.Any">Any</option>
                <option value="@EntityType.Ability">Ability</option>
                <option value="@EntityType.Army" selected>Army</option>
                <option value="@EntityType.Building">Building</option>
                <option value="@EntityType.Building_Upgrade">Building Upgrade</option>
                <option value="@EntityType.Command">Command</option>
                <option value="@EntityType.Faction">Faction</option>
                <option value="@EntityType.Immortal">Immortal</option>
                <option value="@EntityType.Pyre_Spell">Spell</option>
                <option value="@EntityType.Passive">Passive</option>
                <option value="@EntityType.Tech">Tech</option>
                <option value="@EntityType.Worker">Worker</option>
            </ChildContent>
        </FormSelectComponent>


        <FormTextComponent Label="Search Label" Placeholder="Throne..." OnChange="OnSearchTextChanged"/>
    </FormLayoutComponent>

</div>

<style>

.desktopFilters {
    display: flex;
    gap: 12px;
    flex-direction: column;
    justify-content: flex-start;
    justify-items: flex-start;
    top: 50px;
    padding: 12px;
    width: 100%;
    left: 0px;
}

.desktopFiltersContainer {
    width: 75%;
    min-width: 1000px;
    margin: auto;
    display: flex;
    gap: 16px;
    flex-direction: column;
    justify-content: flex-start;
    justify-items: flex-start;
}

.filtersContainer {
    display: flex;
    gap: 16px;
}

.filterContainer {
    display: flex;
    background-color: var(--background);
    gap: 2px;
    margin-right: auto;
    border-radius: 8px;
}

.choiceButton {
    background-color: var(--primary);
    color: white;
    padding: 12px;
    border: 1px solid var(--primary);
}

.choiceButton:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-border-hover);
}

.selected {
    background-color: var(--secondary);
    color: white;
    font-style: normal;
    font-weight: bold;
}

.selected:hover {
    background-color: var(--secondary-hover);
    border-color: var(--secondary-border-hover);
}


.filterContainer .choiceButton:first-child {
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
}


.filterContainer .choiceButton:last-child {
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
}

@@media only screen and (max-width: 1025px) {
    .desktopNavContainer {
        display: none;
    }
}

@@media only screen and (max-width: 480px) {
    .filtersContainer {
        flex-direction: column;
    }

    .filterContainer {
        flex-direction: column;
    }
}

.mobileFilters {
    display: none;
}

@@media only screen and (max-width: 1024px) {
    .mobileFilters {
        display: block;
    }

    .desktopFilters {
        display: none;
    }

    .desktopSpacer {
        display: none;
    }
}
</style>


@code {

    [Inject]
    public IEntityFilterService EntityFilterService { get; set; } = default!;

    protected override void OnInitialized()
    {
    }

    void OnChangeFaction(string clickedFaction)
    {
        EntityFilterService.SelectFactionType(clickedFaction);

        StateHasChanged();
    }

    void OnChangeImmortal(string clickedImmortal)
    {
        EntityFilterService.SelectImmortalType(clickedImmortal);
    }

    void OnChangeEntity(string clickedEntity)
    {
        EntityFilterService.SelectEntityType(clickedEntity);
    }

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

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


    void OnEntityChanged(ChangeEventArgs e)
    {
        EntityFilterService.SelectEntityType(e.Value!.ToString()!);
    }


    void OnSearchTextChanged(ChangeEventArgs e)
    {
        EntityFilterService.EnterSearchText(e.Value!.ToString()!);
    }

}