{{--
    Gallery Filter Slide-over Panel
    ────────────────────────────────────────────────────────────────────────────
    Triggered by:  #gallery-filter-panel-toggle  (in gallery/index.blade.php)
    Controlled by: initGalleryFilterPanel()       (in gallery/index.blade.php scripts)

    Available Blade variables (all optional, safe to omit):
        $sort_options    array   Current sort options list
        $current_sort    string  Active sort value
--}}
<div
    id="gallery-filter-panel"
    role="dialog"
    aria-modal="true"
    aria-label="Gallery filters"
    aria-hidden="true"
    class="fixed inset-0 z-50 pointer-events-none"
>
    {{-- Backdrop --}}
    <div
        id="gallery-filter-backdrop"
        class="absolute inset-0 bg-black/50 backdrop-blur-sm opacity-0 transition-opacity duration-300 ease-out"
        aria-hidden="true"
    ></div>

    {{-- Drawer --}}
    <div
        id="gallery-filter-drawer"
        class="absolute right-0 top-0 bottom-0 w-full md:w-[22rem] bg-nova-800 border-l border-white/10 shadow-2xl
               translate-x-full transition-transform duration-300 ease-out
               flex flex-col overflow-hidden"
    >

        {{-- Header --}}
        <div class="flex items-center justify-between px-5 py-4 border-b border-white/10 shrink-0">
            <h2 class="text-base font-semibold text-white/90">Filters</h2>
            <button
                id="gallery-filter-panel-close"
                type="button"
                class="rounded-lg p-1.5 text-neutral-400 hover:text-white hover:bg-white/10 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/60"
                aria-label="Close filters"
            >
                <svg class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" aria-hidden="true">
                    <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
                </svg>
            </button>
        </div>

        {{-- Scrollable filter body --}}
        <div class="flex-1 overflow-y-auto px-5 py-6 space-y-8">

            {{-- ── Orientation ─────────────────────────────────────────────── --}}
            <fieldset>
                <legend class="text-[11px] font-semibold uppercase tracking-widest text-neutral-500 mb-3">Orientation</legend>
                <div class="flex flex-wrap gap-2">
                    @foreach([['any','Any'],['landscape','Landscape 🖥'],['portrait','Portrait 📱']] as [$val, $label])
                    <label class="nb-filter-choice">
                        <input
                            type="radio"
                            name="orientation"
                            value="{{ $val }}"
                            class="sr-only"
                            {{ (request('orientation', 'any') === $val) ? 'checked' : '' }}
                        >
                        <span class="nb-filter-choice-label">{{ $label }}</span>
                    </label>
                    @endforeach
                </div>
            </fieldset>
            {{-- ── Resolution ─────────────────────────────────────────────────── --}}
            <fieldset>
                <legend class="text-[11px] font-semibold uppercase tracking-widest text-neutral-500 mb-3">Resolution</legend>
                <div class="flex flex-wrap gap-2">
                    @foreach([
                        ['any',   'Any'],
                        ['hd',    'HD 1280×720'],
                        ['fhd',   'Full HD 1920×1080'],
                        ['2k',    '2K 2560×1440'],
                        ['4k',    '4K 3840×2160'],
                    ] as [$val, $label])
                    <label class="nb-filter-choice">
                        <input
                            type="radio"
                            name="resolution"
                            value="{{ $val }}"
                            class="sr-only"
                            {{ (request('resolution', 'any') === $val) ? 'checked' : '' }}
                        >
                        <span class="nb-filter-choice-label">{{ $label }}</span>
                    </label>
                    @endforeach
                </div>
            </fieldset>
            {{-- ── Date Range ───────────────────────────────────────────────── --}}
            <fieldset>
                <legend class="text-[11px] font-semibold uppercase tracking-widest text-neutral-500 mb-3">Date Range</legend>
                <div class="grid grid-cols-2 gap-3">
                    <div>
                        <label class="block text-xs text-neutral-400 mb-1.5" for="fp-date-from">From</label>
                        <input
                            type="date"
                            id="fp-date-from"
                            name="date_from"
                            value="{{ request('date_from') }}"
                            max="{{ date('Y-m-d') }}"
                            class="nb-filter-input w-full"
                        />
                    </div>
                    <div>
                        <label class="block text-xs text-neutral-400 mb-1.5" for="fp-date-to">To</label>
                        <input
                            type="date"
                            id="fp-date-to"
                            name="date_to"
                            value="{{ request('date_to') }}"
                            max="{{ date('Y-m-d') }}"
                            class="nb-filter-input w-full"
                        />
                    </div>
                </div>
            </fieldset>
            {{-- ── Author ──────────────────────────────────────────────────── --}}
            <fieldset>
                <legend class="text-[11px] font-semibold uppercase tracking-widest text-neutral-500 mb-3">Author</legend>
                <input
                    type="text"
                    id="fp-author"
                    name="author"
                    value="{{ request('author') }}"
                    placeholder="Username or display name"
                    autocomplete="off"
                    class="nb-filter-input w-full"
                />
            </fieldset>
            {{-- ── Sort ─────────────────────────────────────────────────────── --}}
            @if(!empty($sort_options))
            <fieldset>
                <legend class="text-[11px] font-semibold uppercase tracking-widest text-neutral-500 mb-3">Sort By</legend>
                <div class="flex flex-col gap-2">
                    @foreach($sort_options as $opt)
                    <label class="nb-filter-choice nb-filter-choice--block">
                        <input
                            type="radio"
                            name="sort"
                            value="{{ $opt['value'] }}"
                            class="sr-only"
                            {{ ($current_sort ?? 'trending') === $opt['value'] ? 'checked' : '' }}
                        >
                        <span class="nb-filter-choice-label w-full text-left">{{ $opt['label'] }}</span>
                    </label>
                    @endforeach
                </div>
            </fieldset>
            @endif

        </div>

        {{-- Footer actions --}}
        <div class="shrink-0 flex items-center gap-3 px-5 py-4 border-t border-white/10 bg-nova-900/40">
            <button
                id="gallery-filter-reset"
                type="button"
                class="flex-1 rounded-lg border border-white/10 bg-white/5 py-2.5 text-sm text-neutral-300 hover:text-white hover:bg-white/10 transition-colors"
            >
                Reset
            </button>
            <button
                id="gallery-filter-apply"
                type="button"
                class="flex-1 rounded-lg bg-accent py-2.5 text-sm font-semibold text-white shadow-sm shadow-accent/30 hover:bg-amber-600 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/60"
            >
                Apply Filters
            </button>
        </div>

    </div>
</div>
