{{-- Quick-view "Genel Bilgiler" tam düzenleme formu (kültür/yurtdışı/günübirlik ortak).
     Gerekli: $tour, $editBase, $cities, $categories, $productType ('cultural'|'international'|'day').
     Opsiyonel: $cancellationPolicies, $termsConditions, $inclusionsTemplates, $exclusionsTemplates --}}
@php
    $productType = $productType ?? 'cultural';
    $isDay = $productType === 'day';
    $categories = $categories ?? collect();
    $cancellationPolicies = $cancellationPolicies ?? collect();
    $selectedCatIds = $tour->categories->pluck('id')->toArray();
    $tourTypeOpts = ['domestic' => 'Yurt İçi', 'international' => 'Yurt Dışı'];
    $difficultyOpts = ['easy' => 'Kolay', 'moderate' => 'Orta', 'challenging' => 'Zor', 'extreme' => 'Çok Zor'];
    $transportOpts = ['air' => 'Uçak', 'road' => 'Karayolu', 'train' => 'Tren', 'ferry' => 'Feribot', 'other' => 'Diğer'];
    $weekdays = ['monday' => 'Pzt', 'tuesday' => 'Sal', 'wednesday' => 'Çar', 'thursday' => 'Per', 'friday' => 'Cum', 'saturday' => 'Cmt', 'sunday' => 'Paz'];
    $recurring = is_array($tour->recurring_days ?? null) ? $tour->recurring_days : [];
@endphp

<form class="qv-gform" data-pqv-save data-method="PUT" data-reload-tab="overview"
      action="{{ route("$editBase.update-general", $tour) }}">

    {{-- Temel Bilgiler --}}
    <div class="pqv-section">
        <div class="pqv-sec-title"><i class="fas fa-info-circle"></i> Temel Bilgiler</div>
        <div class="row g-2">
            <div class="col-md-6"><label class="form-label">Tur Adı *</label>
                <input type="text" name="name" class="form-control" value="{{ $tour->name }}" required></div>
            <div class="col-md-3"><label class="form-label">Tur Tipi *</label>
                <select name="tour_type" class="form-select" required>
                    @foreach($tourTypeOpts as $v => $l)<option value="{{ $v }}" @selected($tour->tour_type === $v)>{{ $l }}</option>@endforeach
                </select></div>
            <div class="col-md-3"><label class="form-label">Zorluk *</label>
                <select name="difficulty_level" class="form-select" required>
                    @foreach($difficultyOpts as $v => $l)<option value="{{ $v }}" @selected($tour->difficulty_level === $v)>{{ $l }}</option>@endforeach
                </select></div>

            <div class="col-md-6"><label class="form-label">Kalkış Şehri *</label>
                <select name="departure_city_id" class="form-select" required>
                    @foreach($cities as $c)<option value="{{ $c->id }}" @selected($tour->departure_city_id == $c->id)>{{ $c->city ?? $c->name }}</option>@endforeach
                </select></div>
            <div class="col-md-6"><label class="form-label">Varış Şehri *</label>
                <select name="arrival_city_id" class="form-select" required>
                    @foreach($cities as $c)<option value="{{ $c->id }}" @selected($tour->arrival_city_id == $c->id)>{{ $c->city ?? $c->name }}</option>@endforeach
                </select></div>

            @if($isDay)
                <div class="col-md-3"><label class="form-label">Başlangıç Saati *</label>
                    <input type="time" name="start_time" class="form-control" value="{{ $tour->start_time ? \Carbon\Carbon::parse($tour->start_time)->format('H:i') : '09:00' }}" required></div>
                <div class="col-md-3"><label class="form-label">Bitiş Saati *</label>
                    <input type="time" name="end_time" class="form-control" value="{{ $tour->end_time ? \Carbon\Carbon::parse($tour->end_time)->format('H:i') : '18:00' }}" required></div>
            @else
                <div class="col-md-3"><label class="form-label">Gün *</label>
                    <input type="number" name="days" class="form-control" min="1" value="{{ $tour->days }}" required></div>
                <div class="col-md-3"><label class="form-label">Gece</label>
                    <input type="number" name="nights" class="form-control" min="0" value="{{ $tour->nights }}"></div>
            @endif

            <div class="col-md-3"><label class="form-label">Min. Katılımcı *</label>
                <input type="number" name="min_participants" class="form-control" min="1" value="{{ $tour->min_participants }}" required></div>
            <div class="col-md-3"><label class="form-label">Maks. Katılımcı</label>
                <input type="number" name="max_participants" class="form-control" min="1" value="{{ $tour->max_participants }}"></div>
            <div class="col-md-3"><label class="form-label">Min. Yaş</label>
                <input type="number" name="min_age" class="form-control" min="0" value="{{ $tour->min_age }}"></div>
            <div class="col-md-3"><label class="form-label">Maks. Yaş</label>
                <input type="number" name="max_age" class="form-control" min="0" value="{{ $tour->max_age }}"></div>

            <div class="col-12"><label class="form-label">Kısa Açıklama</label>
                <textarea name="short_description" class="form-control" rows="2" maxlength="500">{{ $tour->short_description }}</textarea></div>
            <div class="col-12"><label class="form-label">Zorluk Açıklaması</label>
                <textarea name="difficulty_description" class="form-control" rows="2">{{ $tour->difficulty_description }}</textarea></div>

            @if($isDay)
                <div class="col-12">
                    <label class="form-label">Tekrar Günleri</label>
                    <div class="d-flex flex-wrap gap-3">
                        @foreach($weekdays as $v => $l)
                            <label class="form-check-label"><input type="checkbox" name="recurring_days[]" value="{{ $v }}" @checked(in_array($v, $recurring))> {{ $l }}</label>
                        @endforeach
                    </div>
                </div>
            @endif
        </div>
    </div>

    {{-- İçerik (Quill) --}}
    <div class="pqv-section">
        <div class="pqv-sec-title"><i class="fas fa-file-lines"></i> İçerik</div>
        @include('agency.products._qv-quill-field', ['name' => 'description', 'label' => 'Detaylı Açıklama *', 'value' => $tour->description])
        @include('agency.products._qv-quill-field', ['name' => 'places_to_visit', 'label' => 'Gezilecek Yerler', 'value' => $tour->places_to_visit])
        <div class="row g-2">
            <div class="col-md-6">@include('agency.products._qv-quill-field', ['name' => 'inclusions', 'label' => 'Fiyata Dahil', 'value' => $tour->inclusions])</div>
            <div class="col-md-6">@include('agency.products._qv-quill-field', ['name' => 'exclusions', 'label' => 'Fiyata Dahil Değil', 'value' => $tour->exclusions])</div>
        </div>
    </div>

    {{-- Ulaşım (kültür/yurtdışı) --}}
    @unless($isDay)
        <div class="pqv-section">
            <div class="pqv-sec-title"><i class="fas fa-route"></i> Ulaşım</div>
            <div class="row g-2">
                <div class="col-md-4"><label class="form-label">Ulaşım Şekli</label>
                    <select name="transportation_method" class="form-select" data-qg-transport>
                        <option value="">— Seçin —</option>
                        @foreach($transportOpts as $v => $l)<option value="{{ $v }}" @selected($tour->transportation_method === $v)>{{ $l }}</option>@endforeach
                    </select></div>
                <div class="col-md-4 qg-air" style="{{ $tour->transportation_method === 'air' ? '' : 'display:none' }}">
                    <label class="form-label">Uçuş Numarası</label>
                    <input type="text" name="departure_flight_number" class="form-control" value="{{ $tour->departure_flight_number }}"></div>
                <div class="col-md-4 qg-air" style="{{ $tour->transportation_method === 'air' ? '' : 'display:none' }}">
                    <label class="form-label">Uçuş Kalkış Saati</label>
                    <input type="time" name="flight_departure_time" class="form-control" value="{{ $tour->flight_departure_time ? \Carbon\Carbon::parse($tour->flight_departure_time)->format('H:i') : '' }}"></div>

                <div class="col-12 qg-road" style="{{ in_array($tour->transportation_method, ['road','train','ferry','other']) ? '' : 'display:none' }}">
                    <label class="form-check-label mb-2"><input type="checkbox" name="has_transfer_points" value="1" data-qg-transfer-toggle @checked($tour->has_transfer_points)> Transfer noktaları ekle</label>
                    <div data-qg-transfer-wrap style="{{ $tour->has_transfer_points ? '' : 'display:none' }}">
                        <div data-qg-transfer-rows>
                            @foreach($tour->transferPoints as $i => $tp)
                                <div class="row g-2 mb-2 qg-tp-row">
                                    <div class="col-md-4"><input type="text" name="transfer_points[{{ $i }}][location_name]" class="form-control" placeholder="Konum" value="{{ $tp->location_name }}"></div>
                                    <div class="col-md-3"><input type="time" name="transfer_points[{{ $i }}][pickup_time]" class="form-control" value="{{ $tp->pickup_time ? \Carbon\Carbon::parse($tp->pickup_time)->format('H:i') : '' }}"></div>
                                    <div class="col-md-4"><input type="text" name="transfer_points[{{ $i }}][notes]" class="form-control" placeholder="Not" value="{{ $tp->notes }}"></div>
                                    <div class="col-md-1"><button type="button" class="btn btn-sm btn-outline-danger" data-qg-tp-remove><i class="fas fa-times"></i></button></div>
                                    <input type="hidden" name="transfer_points[{{ $i }}][id]" value="{{ $tp->id }}">
                                </div>
                            @endforeach
                        </div>
                        <button type="button" class="btn btn-sm btn-outline-primary" data-qg-tp-add><i class="fas fa-plus"></i> Transfer Noktası</button>
                    </div>
                </div>
                <div class="col-12"><label class="form-label">Ulaşım Notları</label>
                    <textarea name="transportation_notes" class="form-control" rows="2">{{ $tour->transportation_notes }}</textarea></div>
            </div>
        </div>
    @endunless

    {{-- Politikalar --}}
    <div class="pqv-section">
        <div class="pqv-sec-title"><i class="fas fa-file-contract"></i> Politikalar</div>
        <div class="row g-2 mb-2">
            <div class="col-md-4"><label class="form-label">Ücretsiz İptal (saat önce)</label>
                <input type="number" name="cancellation_deadline_hours" class="form-control" min="0" value="{{ $tour->cancellation_deadline_hours }}"></div>
        </div>
        @include('agency.products._qv-quill-field', ['name' => 'cancellation_policy', 'label' => 'İptal Politikası', 'value' => $tour->cancellation_policy])
        @include('agency.products._qv-quill-field', ['name' => 'terms_conditions', 'label' => 'Şartlar & Koşullar', 'value' => $tour->terms_conditions])
    </div>

    {{-- Kategoriler --}}
    <div class="pqv-section">
        <div class="pqv-sec-title"><i class="fas fa-tags"></i> Kategoriler</div>
        @if($categories->count())
            <div class="d-flex flex-wrap gap-3">
                @foreach($categories as $cat)
                    <label class="form-check-label"><input type="checkbox" name="categories[]" value="{{ $cat->id }}" @checked(in_array($cat->id, $selectedCatIds))> {{ $cat->name }}</label>
                @endforeach
            </div>
        @else
            <p class="text-muted small mb-0">Tanımlı kategori yok.</p>
        @endif
    </div>

    <div class="text-end">
        <button type="submit" class="pqv-btn pqv-btn-primary"><i class="fas fa-check"></i> Genel Bilgileri Kaydet</button>
    </div>
</form>
