{{-- Tur liste sayfası — image.png / trivago düzeni: sol filtre paneli + yatay kartlar --}}
@extends('site.templates.voyage.layout', ['pageTitle' => $productType->name . ' | ' . $agency->name])

@section('content')
    <section class="v-page-head v-page-head--band">
        <div class="v-container">
            <nav class="v-breadcrumb">
                <a href="{{ route('customer.agency.show', $agency->slug) }}">Ana Sayfa</a>
                <x-voyage.icon name="chevron-right" />
                <a href="{{ route('customer.agency.tours.index', $agency->slug) }}">Turlarımız</a>
                <x-voyage.icon name="chevron-right" />
                <span>{{ $productType->name }}</span>
            </nav>
            <h1 class="v-page-head__title">{{ $productType->name }}</h1>
        </div>
    </section>

    <section class="v-section v-section--canvas v-listing">
        <div class="v-container v-listing__layout">

            {{-- Sol filtre paneli (trivago deseni) --}}
            <aside class="v-filter-sidebar" id="vFilterSidebar">
                <form method="GET" action="{{ route('customer.agency.tours.list', ['agency' => $agency->slug, 'type' => $productType->route_slug]) }}" id="vFilterForm">
                    <div class="v-filter-sidebar__head">
                        <strong><x-voyage.icon name="search" /> Filtreler</strong>
                        @if(array_filter($filters))
                            <a href="{{ route('customer.agency.tours.list', ['agency' => $agency->slug, 'type' => $productType->route_slug]) }}" class="v-filter-sidebar__reset">Temizle</a>
                        @endif
                    </div>

                    <div class="v-filter-group">
                        <label class="v-filter-group__title" for="vFilterQ">Arama</label>
                        <input type="text" id="vFilterQ" name="q" value="{{ $filters['q'] ?? '' }}" placeholder="Tur adı ya da bölge" class="v-filter-input">
                    </div>

                    @if($productType->code !== 'gunubirlik-tur')
                        <div class="v-filter-group">
                            <span class="v-filter-group__title">Süre</span>
                            @php $currentDuration = ($filters['min_days'] ?? '') . '-' . ($filters['max_days'] ?? ''); @endphp
                            @foreach([['', '', 'Tümü'], ['1', '3', '1 - 3 Gün'], ['4', '6', '4 - 6 Gün'], ['7', '', '7 Gün ve üzeri']] as [$min, $max, $label])
                                <label class="v-filter-check">
                                    <input type="radio" name="duration" value="{{ $min }}-{{ $max }}"
                                           data-min="{{ $min }}" data-max="{{ $max }}"
                                           {{ $currentDuration === $min . '-' . $max ? 'checked' : '' }}>
                                    <span>{{ $label }}</span>
                                </label>
                            @endforeach
                            <input type="hidden" name="min_days" value="{{ $filters['min_days'] ?? '' }}">
                            <input type="hidden" name="max_days" value="{{ $filters['max_days'] ?? '' }}">
                        </div>
                    @endif

                    @if($categories->isNotEmpty())
                        <div class="v-filter-group">
                            <span class="v-filter-group__title">Kategori</span>
                            <label class="v-filter-check">
                                <input type="radio" name="category_id" value="" {{ empty($filters['category_id']) ? 'checked' : '' }}>
                                <span>Tümü</span>
                            </label>
                            @foreach($categories as $category)
                                <label class="v-filter-check">
                                    <input type="radio" name="category_id" value="{{ $category->id }}"
                                           {{ (string) ($filters['category_id'] ?? '') === (string) $category->id ? 'checked' : '' }}>
                                    <span>{{ $category->name }}</span>
                                </label>
                            @endforeach
                        </div>
                    @endif

                    <button type="submit" class="v-btn v-btn--primary v-btn--block">Sonuçları Göster</button>
                </form>
            </aside>

            {{-- Liste --}}
            <div class="v-listing__results">
                <div class="v-listing__bar">
                    <span class="v-listing__count"><strong>{{ $tours->total() }}</strong> tur bulundu</span>
                    <div class="v-listing__sort">
                        <label for="vSort">Sıralama:</label>
                        <select id="vSort" name="sort" form="vFilterForm" onchange="document.getElementById('vFilterForm').submit()">
                            <option value="recommended" {{ ($filters['sort'] ?? 'recommended') === 'recommended' ? 'selected' : '' }}>Önerilen</option>
                            <option value="newest" {{ ($filters['sort'] ?? '') === 'newest' ? 'selected' : '' }}>En Yeni</option>
                            <option value="name" {{ ($filters['sort'] ?? '') === 'name' ? 'selected' : '' }}>İsme Göre</option>
                        </select>
                    </div>
                    <button type="button" class="v-btn v-btn--ghost v-btn--sm v-listing__filter-toggle" id="vFilterToggle">
                        <x-voyage.icon name="search" /> Filtreler
                    </button>
                </div>

                @if(!empty($filters['q']))
                    <div class="v-chip-row">
                        <span class="v-chip">
                            "{{ $filters['q'] }}"
                            <a href="{{ route('customer.agency.tours.list', array_filter(['agency' => $agency->slug, 'type' => $productType->route_slug, 'category_id' => $filters['category_id'] ?? null])) }}" aria-label="Kaldır"><x-voyage.icon name="x" /></a>
                        </span>
                    </div>
                @endif

                <div class="v-listing__cards">
                    @forelse($tours as $tour)
                        @include('site.templates.voyage.partials.tour-card', [
                            'tour' => $tour,
                            'type' => $productType,
                            'variant' => 'horizontal',
                        ])
                    @empty
                        <div class="v-empty-state">
                            <x-voyage.icon name="search" />
                            <h2>Sonuç bulunamadı</h2>
                            <p>Filtreleri değiştirmeyi deneyin ya da tüm turlara göz atın.</p>
                        </div>
                    @endforelse
                </div>

                <div class="v-pagination">
                    {{ $tours->links('site.templates.voyage.partials.pagination') }}
                </div>
            </div>
        </div>
    </section>
@endsection
