<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 || $categories )
            <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">
            {{-- Categories --}}
            <x-database-filter-without-mode title="Categories" :items="$allCategories" model="categories" />
        </aside>

    <div class="database-results">
        <div class="database-sort">
            @foreach( \App\Livewire\NewsDatabase::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">{{ $news->total() }} results</span>
        </div>

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

        {{ $news->links() }}

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