<div @filters-updated.window="refreshIcons($el)">
    <div class="database-search filter-bar">
        <input
            type="text"
            wire:model.live.debounce="search"
            placeholder="Search..."
            class="form-input filter-bar-search"
        >
        @if( $search || $types || $platforms || $games || $statuses || $authors || $languages || $modifications || $categories || $levels || $systems || $userId )
            <button type="button" wire:click="clearFilters" class="btn">
                <i data-lucide="x"></i> Clear filters
            </button>
        @endif
    </div>
    <div class="database-wrapper">
        <aside class="database-filters">

            {{-- Types --}}
            <div class="filter-group" x-data="{open: true}">
                <div class="filter-title-row" @click="open = !open">
                    <h4 class="filter-title">Type</h4>
                    <i data-lucide="chevron-down" size="14" class="filter-chevron" :class="{ 'rotated': !open }"></i>
                </div>
                <div class="filter-options" x-show="open" x-transition>
                    @foreach( \App\Livewire\Database::ENTRY_TYPES as $k => $v )
                        <label class="filter-option">
                            <input type="checkbox" wire:model.live="types" value="{{ $k }}">
                            {{ $v }}
                        </label>
                    @endforeach
                </div>
            </div>

            {{-- Games --}}
            <x-database-filter-without-mode-search title="Game" :items="$allGames" model="games" search-model="gameSearch" />

            {{-- Platforms --}}
            <x-database-filter-without-mode title="Platform" :items="$allPlatforms" model="platforms"/>

            {{-- Genres --}}
            <x-database-filter-without-mode title="Genre" :items="$allGenres" model="genres"/>

            {{-- Statuses --}}
            <x-database-filter-without-mode title="Status" :items="$allStatuses" model="statuses"/>

            {{-- Authors --}}
            <x-database-filter-with-mode-search title="Authors" :items="$allAuthors" search-model="authorSearch" model="authors" mode-model="authorsMode" :selected-mode="$authorsMode" />

            {{-- Languages --}}
            <x-database-filter-with-mode title="Languages" :items="$allLanguages" model="languages" mode-model="languagesMode" :selected-mode="$languagesMode" />

            {{-- Modifications --}}
            <x-database-filter-with-mode title="Modifications" :items="$allModifications" model="modifications" mode-model="modificationsMode" :selected-mode="$modificationsMode" />

            {{-- Categories --}}
            <x-database-filter-with-mode title="Categories" :items="$allCategories" model="categories" mode-model="categoriesMode" :selected-mode="$categoriesMode" />

            {{-- Levels --}}
            <x-database-filter-without-mode title="Level" :items="$allLevels" model="levels"/>

            {{-- Systems --}}
            <x-database-filter-with-mode title="Systems" :items="$allSystems" model="systems" mode-model="systemsMode" :selected-mode="$systemsMode" />

        </aside>

        <div class="database-results">
            <div class="database-sort">
                @foreach( \App\Livewire\Database::SORT_OPTIONS as $k => $v )
                    <button type="button" wire:click="setSort('{{ $k }}')" class="btn {{ $sortBy === $k ? 'active' : '' }}">
                        {{ $v }}
                    </button>
                    @if( $sortBy === $k )
                        <i data-lucide="{{ $sortDir === 'asc' ? 'arrow-up' : 'arrow-down' }}"></i>
                    @endif
                @endforeach
                <span class="database-results-count">{{ $entries->total() }} results</span>
            </div>

            <div class="grid-entries">
                @forelse($entries as $entry)
                    <x-entry-card :entry="$entry" />
                @empty
                    <p>No entries found.</p>
                @endforelse
            </div>

            {{ $entries->links() }}

        </div>
    </div>
</div>
