{{-- Quick-view "Genel Bilgiler" — ANLIK alan-alan inline düzenleme (kaydet butonu YOK).
     Skalerler _qv-field (blur/Enter → update-field), HTML alanları _qv-quill-inline (blur → update-field),
     repeater/kategori blokları _qv-inline-blocks (değişince otomatik PATCH).
     Gerekli: $tour, $editBase, $cities, $categories, $productType ('cultural'|'international'|'day').
     Opsiyonel: $uf --}}
@php
    $productType = $productType ?? 'cultural';
    $isDay = $productType === 'day';
    $categories = $categories ?? collect();
    $selectedCatIds = $tour->categories->pluck('id')->toArray();
    $uf = $uf ?? route("$editBase.update-field", $tour);
    // Transfer noktaları yalnızca kültür/yurtdışında var; günübirlikte route da tanımlı değil.
    $transferUrl = $isDay ? null : route("$editBase.transfer-points", $tour);
    $catUrl = route("$editBase.categories", $tour);
    $cityOptions = collect($cities)->map(fn($c) => ['value' => (string) $c->id, 'label' => $c->city ?? $c->name])->values();
    $tourTypeOptions = [['value' => 'domestic', 'label' => 'Yurt İçi'], ['value' => 'international', 'label' => 'Yurt Dışı']];
    $difficultyOptions = [['value' => 'easy', 'label' => 'Kolay'], ['value' => 'moderate', 'label' => 'Orta'], ['value' => 'challenging', 'label' => 'Zor'], ['value' => 'extreme', 'label' => 'Çok Zor']];
    $transportOptions = ['air' => 'Uçak', 'road' => 'Karayolu', 'train' => 'Tren', 'ferry' => 'Feribot', 'other' => 'Diğer'];
    $depCityDisplay = optional($tour->departureCity)->city ?? optional($tour->departureCity)->name ?? '—';
    $arrCityDisplay = optional($tour->arrivalCity)->city ?? optional($tour->arrivalCity)->name ?? '—';
    $flightTime = $tour->flight_departure_time ? \Carbon\Carbon::parse($tour->flight_departure_time)->format('H:i') : '';
    // Günübirliğe özel: saatler + tekrar eden günler (statik general.blade ile birebir)
    $startTime = $isDay && $tour->start_time ? substr((string) $tour->start_time, 0, 5) : '';
    $endTime   = $isDay && $tour->end_time ? substr((string) $tour->end_time, 0, 5) : '';
    $weekdays = ['monday' => 'Pazartesi', 'tuesday' => 'Salı', 'wednesday' => 'Çarşamba', 'thursday' => 'Perşembe', 'friday' => 'Cuma', 'saturday' => 'Cumartesi', 'sunday' => 'Pazar'];
    $selectedDays = is_array($tour->recurring_days ?? null) ? $tour->recurring_days : [];
@endphp

{{-- Kalkış Noktaları (departure points) — modern timeline arayüzü --}}
<style>
    .dp-block { margin-top: 4px; }
    .dp-toggle { display:flex; align-items:center; gap:14px; cursor:pointer; padding:12px 15px; border:1px solid #e7e9f2; border-radius:14px; background:linear-gradient(180deg,#fbfbff,#f5f6fc); transition:border-color .2s, box-shadow .2s; }
    .dp-toggle:hover { border-color:#c7d2fe; box-shadow:0 3px 12px -6px rgba(79,70,229,.35); }
    .dp-toggle > input { position:absolute; opacity:0; width:0; height:0; }
    .dp-toggle-track { position:relative; width:44px; height:25px; border-radius:20px; background:#cbd5e1; flex:none; transition:background .25s; }
    .dp-toggle-thumb { position:absolute; top:3px; left:3px; width:19px; height:19px; border-radius:50%; background:#fff; box-shadow:0 1px 3px rgba(0,0,0,.28); transition:transform .25s; }
    .dp-toggle > input:checked + .dp-toggle-track { background:linear-gradient(135deg,#6366f1,#4f46e5); }
    .dp-toggle > input:checked + .dp-toggle-track .dp-toggle-thumb { transform:translateX(19px); }
    .dp-toggle > input:focus-visible + .dp-toggle-track { box-shadow:0 0 0 3px rgba(79,70,229,.25); }
    .dp-toggle-title { font-weight:800; font-size:.9rem; color:#1e293b; display:flex; align-items:center; gap:8px; }
    .dp-toggle-title i { color:#4f46e5; }
    .dp-toggle-sub { display:block; font-size:.74rem; color:#94a3b8; margin-top:3px; line-height:1.35; }
    .dp-wrap { margin-top:12px; }
    .dp-rows { counter-reset: dp; position:relative; display:flex; flex-direction:column; gap:6px; margin-bottom:12px; }
    .dp-row { counter-increment: dp; display:flex; align-items:center; gap:13px; position:relative; padding:3px 0; }
    .dp-row::before { content:''; position:absolute; left:16px; top:0; bottom:0; width:2px; background:linear-gradient(#e0e7ff,#eef2ff); z-index:0; }
    .dp-row:first-child::before { top:50%; }
    .dp-row:last-child::before { bottom:50%; }
    .dp-row:only-child::before { display:none; }
    .dp-marker { position:relative; z-index:1; width:34px; height:34px; flex:none; border-radius:50%; background:linear-gradient(135deg,#6366f1,#4f46e5); color:#fff; display:flex; align-items:center; justify-content:center; font-weight:800; font-size:.82rem; box-shadow:0 4px 11px -3px rgba(79,70,229,.55); }
    .dp-marker::before { content: counter(dp); }
    .dp-fields { flex:1; display:flex; gap:8px; align-items:stretch; min-width:0; }
    .dp-field { display:flex; align-items:center; gap:8px; background:#fff; border:1px solid #e7e9f2; border-radius:11px; padding:0 12px; transition:border-color .15s, box-shadow .15s; }
    .dp-field:focus-within { border-color:#4f46e5; box-shadow:0 0 0 3px rgba(79,70,229,.1); }
    .dp-field > i { color:#a3aabf; font-size:.8rem; flex:none; transition:color .15s; }
    .dp-field:focus-within > i { color:#4f46e5; }
    .dp-input { border:none; outline:none; background:transparent; padding:10px 0; font-size:.84rem; color:#1e293b; width:100%; min-width:0; font-weight:500; }
    .dp-input::placeholder { color:#b4bccd; font-weight:400; }
    .dp-loc { flex:1.5; }
    .dp-time { width:118px; flex:none; }
    .dp-note { flex:1; }
    .dp-del { flex:none; width:34px; height:34px; border-radius:10px; border:1px solid #fde2e2; background:#fff; color:#ef4444; cursor:pointer; transition:.15s; display:flex; align-items:center; justify-content:center; }
    .dp-del:hover { background:#ef4444; color:#fff; border-color:#ef4444; transform:rotate(90deg); }
    .dp-add { display:inline-flex; align-items:center; gap:8px; border:1.5px dashed #c7d2fe; background:#f5f3ff; color:#4f46e5; font-weight:700; font-size:.82rem; border-radius:11px; padding:10px 17px; cursor:pointer; transition:.15s; }
    .dp-add:hover { background:#4f46e5; color:#fff; border-color:#4f46e5; transform:translateY(-1px); box-shadow:0 7px 18px -6px rgba(79,70,229,.55); }
    @media (max-width:640px){ .dp-fields{flex-wrap:wrap} .dp-time{width:100%} .dp-note{flex:1 1 100%} }
</style>

{{-- .qv-gform sarmalayıcı: _qv-general-ui'nin ulaşım göster/gizle mantığı bu class'a dayanır (form DEĞİL) --}}
<div class="qv-gform">

    {{-- Temel Bilgiler --}}
    <div class="pqv-section">
        <div class="pqv-sec-title"><i class="fas fa-info-circle"></i> Temel Bilgiler</div>
        {{-- Tur adı: tam satır + geniş input (uzun adlar için) --}}
        @include('agency.products._qv-field', ['field' => 'name', 'label' => 'Tur Adı', 'display' => $tour->name, 'itemClass' => 'full mb-3', 'wide' => true])
        <div class="pqv-grid">
            @include('agency.products._qv-field', ['field' => 'tour_type', 'label' => 'Tur Tipi', 'type' => 'select', 'options' => $tourTypeOptions, 'current' => $tour->tour_type, 'display' => $tour->tour_type_display_name ?? $tour->tour_type, 'wide' => true])
            @if($isDay)
                @include('agency.products._qv-field', ['field' => 'start_time', 'label' => 'Başlangıç Saati', 'type' => 'time', 'current' => $startTime, 'display' => $startTime ?: '—'])
                @include('agency.products._qv-field', ['field' => 'end_time', 'label' => 'Bitiş Saati', 'type' => 'time', 'current' => $endTime, 'display' => $endTime ?: '—'])
            @else
                @include('agency.products._qv-field', ['field' => 'days', 'label' => 'Gün', 'type' => 'number', 'display' => $tour->days])
                @include('agency.products._qv-field', ['field' => 'nights', 'label' => 'Gece', 'type' => 'number', 'display' => $tour->nights])
            @endif
        </div>
        <div class="d-grid gap-3 mt-2">
            @include('agency.products._qv-field', ['field' => 'short_description', 'label' => 'Kısa Açıklama', 'type' => 'textarea', 'display' => $tour->short_description])
        </div>
    </div>

    {{-- Konum Bilgileri (statik general.blade "Konum Bilgileri" ile birebir) --}}
    <div class="pqv-section">
        <div class="pqv-sec-title"><i class="fas fa-map-marker-alt"></i> Konum Bilgileri</div>
        <div class="pqv-grid">
            @include('agency.products._qv-field', ['field' => 'departure_city_id', 'label' => 'Kalkış Şehri', 'type' => 'select', 'options' => $cityOptions, 'current' => (string) $tour->departure_city_id, 'display' => $depCityDisplay, 'wide' => true])
            @include('agency.products._qv-field', ['field' => 'arrival_city_id', 'label' => 'Varış Şehri', 'type' => 'select', 'options' => $cityOptions, 'current' => (string) $tour->arrival_city_id, 'display' => $arrCityDisplay, 'wide' => true])
        </div>
    </div>

    {{-- Kapasite ve Yaş Sınırları (statik general.blade ile birebir) --}}
    <div class="pqv-section">
        <div class="pqv-sec-title"><i class="fas fa-users"></i> Kapasite ve Yaş Sınırları</div>
        <div class="pqv-grid">
            @include('agency.products._qv-field', ['field' => 'min_participants', 'label' => 'Min. Katılımcı', 'type' => 'number', 'display' => $tour->min_participants])
            @include('agency.products._qv-field', ['field' => 'max_participants', 'label' => 'Maks. Katılımcı', 'type' => 'number', 'display' => $tour->max_participants])
            @include('agency.products._qv-field', ['field' => 'min_age', 'label' => 'Min. Yaş', 'type' => 'number', 'display' => $tour->min_age])
            @include('agency.products._qv-field', ['field' => 'max_age', 'label' => 'Maks. Yaş', 'type' => 'number', 'display' => $tour->max_age])
            @include('agency.products._qv-field', ['field' => 'difficulty_level', 'label' => 'Zorluk Seviyesi', 'type' => 'select', 'options' => $difficultyOptions, 'current' => $tour->difficulty_level, 'display' => $tour->difficulty_level_display_name ?? $tour->difficulty_level, 'wide' => true])
        </div>
        <div class="d-grid gap-3 mt-2">
            @include('agency.products._qv-field', ['field' => 'difficulty_description', 'label' => 'Zorluk Açıklaması', 'type' => 'textarea', 'display' => $tour->difficulty_description])
        </div>
    </div>

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

    {{-- Tekrar Eden Günler (günübirliğe özel) --}}
    @if($isDay)
        <div class="pqv-section">
            <div class="pqv-sec-title"><i class="fas fa-calendar-week"></i> Tekrar Eden Günler</div>
            <div class="d-flex flex-wrap gap-3" data-qv-csv-save="{{ $uf }}" data-field="recurring_days">
                @foreach($weekdays as $key => $name)
                    <label class="form-check-label"><input type="checkbox" value="{{ $key }}" @checked(in_array($key, $selectedDays))> {{ $name }}</label>
                @endforeach
            </div>
            <span class="form-text">Turun tekrar edeceği günleri seçin. Seçili günlerde otomatik tarihler oluşturulacaktır.</span>
        </div>
    @endif

    {{-- 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 align-items-end">
                <div class="col-md-4">
                    <label class="form-label">Ulaşım Şekli</label>
                    <select class="form-select" data-qg-transport data-qv-field-save data-field="transportation_method" data-qv-url="{{ $uf }}">
                        <option value="">— Seçin —</option>
                        @foreach($transportOptions as $v => $l)<option value="{{ $v }}" @selected($tour->transportation_method === $v)>{{ $l }}</option>@endforeach
                    </select>
                </div>
                <div class="col-12 qg-air" style="{{ $tour->transportation_method === 'air' ? '' : 'display:none' }}">
                    <div class="pqv-grid">
                        @include('agency.products._qv-field', ['field' => 'departure_airports', 'label' => 'Kalkış Havalimanı', 'display' => $tour->departure_airports, 'wide' => true])
                        @include('agency.products._qv-field', ['field' => 'arrival_airports', 'label' => 'Varış Havalimanı', 'display' => $tour->arrival_airports, 'wide' => true])
                        @include('agency.products._qv-field', ['field' => 'departure_flight_number', 'label' => 'Uçuş Numarası', 'display' => $tour->departure_flight_number, 'wide' => true])
                        @include('agency.products._qv-field', ['field' => 'flight_departure_time', 'label' => 'Uçuş Kalkış Saati', 'type' => 'time', 'current' => $flightTime, 'display' => $flightTime ?: '—', 'wide' => true])
                    </div>
                </div>

                <div class="col-12 qg-road" data-qv-transfer-save="{{ $transferUrl }}" style="{{ in_array($tour->transportation_method, ['road','train','ferry','other']) ? '' : 'display:none' }}">
                    <div class="dp-block">
                        <label class="dp-toggle">
                            <input type="checkbox" data-qg-transfer-toggle value="1" @checked($tour->has_transfer_points)>
                            <span class="dp-toggle-track"><span class="dp-toggle-thumb"></span></span>
                            <span class="dp-toggle-text">
                                <span class="dp-toggle-title"><i class="fas fa-map-location-dot"></i> Kalkış Noktaları</span>
                                <span class="dp-toggle-sub">Yolcuların bineceği kalkış/buluşma noktalarını ve saatlerini tanımlayın</span>
                            </span>
                        </label>
                        <div class="dp-wrap" data-qg-transfer-wrap style="{{ $tour->has_transfer_points ? '' : 'display:none' }}">
                            <div class="dp-rows" data-qg-transfer-rows>
                                @foreach($tour->transferPoints as $i => $tp)
                                    <div class="dp-row qg-tp-row">
                                        <div class="dp-marker"></div>
                                        <div class="dp-fields">
                                            <div class="dp-field dp-loc">
                                                <i class="fas fa-location-dot"></i>
                                                <input type="text" data-tp="location_name" class="dp-input" placeholder="Kalkış noktası (ör. Taksim Meydanı)" value="{{ $tp->location_name }}">
                                            </div>
                                            <div class="dp-field dp-time">
                                                <i class="fas fa-clock"></i>
                                                <input type="time" data-tp="pickup_time" class="dp-input" value="{{ $tp->pickup_time ? \Carbon\Carbon::parse($tp->pickup_time)->format('H:i') : '' }}">
                                            </div>
                                            <div class="dp-field dp-note">
                                                <i class="fas fa-pen"></i>
                                                <input type="text" data-tp="notes" class="dp-input" placeholder="Not (opsiyonel)" value="{{ $tp->notes }}">
                                            </div>
                                        </div>
                                        <button type="button" class="dp-del" data-qg-tp-remove title="Kalkış noktasını kaldır"><i class="fas fa-xmark"></i></button>
                                        <input type="hidden" data-tp="id" value="{{ $tp->id }}">
                                    </div>
                                @endforeach
                            </div>
                            <button type="button" class="dp-add" data-qg-tp-add><i class="fas fa-plus"></i> Kalkış Noktası Ekle</button>
                        </div>
                    </div>
                </div>

                <div class="col-12 mt-2">
                    @include('agency.products._qv-field', ['field' => 'transportation_notes', 'label' => 'Ulaşım Notları', 'type' => 'textarea', 'display' => $tour->transportation_notes])
                </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="pqv-grid mb-2">
            @include('agency.products._qv-field', ['field' => 'cancellation_deadline_hours', 'label' => 'Ücretsiz İptal (saat önce)', 'type' => 'number', 'display' => $tour->cancellation_deadline_hours])
        </div>
        @include('agency.products._qv-quill-inline', ['name' => 'cancellation_policy', 'label' => 'İptal Politikası', 'value' => $tour->cancellation_policy, 'uf' => $uf, 'templates' => $cancellationPolicies ?? null])
        @include('agency.products._qv-quill-inline', ['name' => 'terms_conditions', 'label' => 'Şartlar & Koşullar', 'value' => $tour->terms_conditions, 'uf' => $uf, 'templates' => $termsConditions ?? null])
    </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" data-qv-cat-save="{{ $catUrl }}">
                @foreach($categories as $cat)
                    <label class="form-check-label"><input type="checkbox" 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>
