
<?php
    $productType = $productType ?? 'day';
    $isDay = $productType === 'day';
    $categories = $categories ?? collect();
    $selectedCatIds = $tour->categories->pluck('id')->toArray();
    $uf = $uf ?? route("$editBase.update-field", $tour);
    $transferUrl = 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])
        ->prepend(['value' => '', 'label' => '—'])->values()->all();
    $tourTypeOptions = [['value' => 'domestic', 'label' => 'Yurt İçi'], ['value' => 'international', 'label' => 'Yurt Dışı']];
    $difficultyOptions = [['value' => '', 'label' => '—'], ['value' => 'easy', 'label' => 'Kolay'], ['value' => 'moderate', 'label' => 'Orta'], ['value' => 'challenging', 'label' => 'Zor'], ['value' => 'extreme', 'label' => 'Çok Zor']];
    // Ulaşım (kültür/yurtdışı): şekle göre uçuş bilgileri ya da kalkış noktaları açılır
    $transportOptions = [['value' => '', 'label' => '—'], ['value' => 'air', 'label' => 'Uçak'], ['value' => 'road', 'label' => 'Karayolu'], ['value' => 'train', 'label' => 'Tren'], ['value' => 'ferry', 'label' => 'Feribot'], ['value' => 'other', 'label' => 'Diğer']];
    $flightTime = $tour->flight_departure_time ? \Carbon\Carbon::parse($tour->flight_departure_time)->format('H:i') : '';

    /** Seçim listesinde değerin etiketini bulur ("—" değer sayılmaz). */
    $optLabel = function (array $opts, $value) {
        foreach ($opts as $o) {
            if ((string) $o['value'] === (string) $value) return $o['label'] === '—' ? '' : $o['label'];
        }
        return (string) ($value ?? '');
    };

    /** Tek satır tanımı — müşteri Künyesindeki $row ile aynı sözleşme. */
    $row = function (string $label, ?string $field, $value, ?string $text = null, array $o = []) {
        return [
            'label' => $label,
            'field' => $field,
            'type' => $o['type'] ?? 'text',
            'value' => $value === null ? '' : (string) $value,
            'text' => $text === null ? ($value === null ? '' : (string) $value) : $text,
            'options' => $o['options'] ?? null,
            'mono' => $o['mono'] ?? false,
            'ph' => $o['ph'] ?? null,
        ];
    };

    $startTime = $tour->start_time ? substr((string) $tour->start_time, 0, 5) : '';
    $endTime = $tour->end_time ? substr((string) $tour->end_time, 0, 5) : '';

    // Temel Bilgiler: günübirlikte saatler, çok günlü turlarda Gün/Gece
    $basicRows = [
        $row('Tur Adı', 'name', $tour->name, null, ['ph' => 'Tur adı']),
        $row('Tur Tipi', 'tour_type', $tour->tour_type, $optLabel($tourTypeOptions, $tour->tour_type), ['type' => 'select', 'options' => $tourTypeOptions]),
    ];
    if ($isDay) {
        $basicRows[] = $row('Başlangıç Saati', 'start_time', $startTime, $startTime, ['type' => 'time', 'mono' => true]);
        $basicRows[] = $row('Bitiş Saati', 'end_time', $endTime, $endTime, ['type' => 'time', 'mono' => true]);
    } else {
        $basicRows[] = $row('Gün', 'days', $tour->days, null, ['type' => 'number', 'mono' => true]);
        $basicRows[] = $row('Gece', 'nights', $tour->nights, null, ['type' => 'number', 'mono' => true]);
    }
    $basicRows[] = $row('Kısa Açıklama', 'short_description', $tour->short_description, null, ['type' => 'textarea', 'ph' => 'Listelerde görünen 1-2 cümlelik tanıtım']);

    $sections = [
        ['title' => 'Temel Bilgiler', 'icon' => 'fa-circle-info', 'rows' => $basicRows],
        ['title' => 'Konum Bilgileri', 'icon' => 'fa-map-marker-alt', 'rows' => [
            $row('Kalkış Şehri', 'departure_city_id', (string) $tour->departure_city_id, $optLabel($cityOptions, $tour->departure_city_id), ['type' => 'select', 'options' => $cityOptions]),
            $row('Varış Şehri', 'arrival_city_id', (string) $tour->arrival_city_id, $optLabel($cityOptions, $tour->arrival_city_id), ['type' => 'select', 'options' => $cityOptions]),
        ]],
        ['title' => 'Kapasite ve Yaş Sınırları', 'icon' => 'fa-users', 'rows' => [
            $row('Min. Katılımcı', 'min_participants', $tour->min_participants, null, ['type' => 'number', 'mono' => true]),
            $row('Maks. Katılımcı', 'max_participants', $tour->max_participants, null, ['type' => 'number', 'mono' => true]),
            $row('Min. Yaş', 'min_age', $tour->min_age, null, ['type' => 'number', 'mono' => true]),
            $row('Maks. Yaş', 'max_age', $tour->max_age, null, ['type' => 'number', 'mono' => true]),
            $row('Zorluk Seviyesi', 'difficulty_level', $tour->difficulty_level, $optLabel($difficultyOptions, $tour->difficulty_level), ['type' => 'select', 'options' => $difficultyOptions]),
            $row('Zorluk Açıklaması', 'difficulty_description', $tour->difficulty_description, null, ['type' => 'textarea', 'ph' => 'Zorluk hakkında not']),
        ]],
    ];

    // Boş alan sayacı ortak ledger-card partial'ında hesaplanır.
?>


<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%} }

    /* ── Kategoriler: seçilebilir chip bulutu ── */
    .qcat-cloud { display:flex; flex-wrap:wrap; gap:8px; }
    .qcat-chip { position:relative; cursor:pointer; margin:0; }
    .qcat-chip input { position:absolute; opacity:0; pointer-events:none; }
    .qcat-face { display:inline-flex; align-items:center; gap:0; padding:8px 15px; border-radius:999px; border:1.5px solid #e2e8f0;
        background:#fff; color:#475569; font-size:.82rem; font-weight:700; line-height:1; user-select:none;
        transition:all .18s cubic-bezier(.34,1.3,.6,1); }
    .qcat-face i { font-size:.6rem; width:0; opacity:0; overflow:hidden; transform:scale(.4) rotate(-90deg); transition:all .18s cubic-bezier(.34,1.3,.6,1); }
    .qcat-chip:hover .qcat-face { border-color:#c7d2fe; color:#4f46e5; transform:translateY(-1px); box-shadow:0 4px 10px -4px rgba(79,70,229,.35); }
    .qcat-chip input:checked + .qcat-face { background:linear-gradient(135deg,#6366f1,#4f46e5); border-color:transparent; color:#fff; box-shadow:0 5px 14px -4px rgba(79,70,229,.55); }
    .qcat-chip input:checked + .qcat-face i { width:.68rem; margin-right:7px; opacity:1; transform:none; }
    .qcat-chip input:focus-visible + .qcat-face { box-shadow:0 0 0 3px rgba(79,70,229,.25); }
    @keyframes qcatPop { 0%{transform:scale(.6);opacity:0} 70%{transform:scale(1.06)} 100%{transform:scale(1);opacity:1} }
    .qcat-chip.is-new { animation:qcatPop .32s cubic-bezier(.34,1.4,.5,1); }
    .qcat-empty { font-size:.78rem; margin:8px 0 0; }

    /* ── Hızlı kategori ekle: kesikli pill giriş ── */
    .qv-cat-add { display:flex; align-items:center; gap:8px; margin-top:14px; max-width:400px; padding:5px 5px 5px 15px;
        border:1.5px dashed #c7d2fe; border-radius:999px; background:#fafaff; transition:border .18s, background .18s, box-shadow .18s; }
    .qv-cat-add:focus-within { border-style:solid; border-color:#4f46e5; background:#fff; box-shadow:0 0 0 3px rgba(79,70,229,.1); }
    .qv-cat-add > i { color:#a5b4fc; font-size:.78rem; flex:none; }
    .qv-cat-add input { flex:1; min-width:0; border:none; outline:none; background:transparent; padding:7px 0;
        font-size:.84rem; font-weight:600; color:#1e293b; }
    .qv-cat-add input::placeholder { color:#a3aabf; font-weight:400; }
    .qv-cat-add button { flex:none; display:inline-flex; align-items:center; gap:6px; border:none; border-radius:999px; cursor:pointer;
        background:linear-gradient(135deg,#6366f1,#4f46e5); color:#fff; font-weight:800; font-size:.78rem; padding:9px 17px;
        box-shadow:0 4px 10px -4px rgba(79,70,229,.5); transition:transform .15s, box-shadow .15s, opacity .15s; }
    .qv-cat-add button:hover:not(:disabled) { transform:translateY(-1px); box-shadow:0 7px 16px -5px rgba(79,70,229,.6); }
    .qv-cat-add button:disabled { opacity:.5; cursor:wait; }
</style>


<div class="qv-gform qv-left-stack">

    
    <?php echo $__env->make('components.quick-view.ledger-card', ['card' => [
        'title' => 'Genel Bilgiler',
        'icon' => 'fa-circle-info',
        'url' => $uf,
        'sections' => $sections,
    ]], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

    
    <div class="pfx">
        <div class="pfx-top">
            <span class="pfx-top-t"><i class="fas fa-file-lines"></i> İçerik</span>
        </div>
        <div class="pfx-body">
            
            <?php echo $__env->make('agency.products._qv-quill-inline', ['name' => 'description', 'label' => 'Detaylı Açıklama', 'value' => $tour->description, 'uf' => $uf, 'defs' => null], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
            <?php echo $__env->make('agency.products._qv-quill-inline', ['name' => 'places_to_visit', 'label' => 'Gezilecek Yerler', 'value' => $tour->places_to_visit, 'uf' => $uf, 'defs' => $attractions ?? null, 'defsMode' => 'item', 'defsLabel' => 'Gezilecek yer ekle', 'defsIcon' => 'fa-map-location-dot'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
            <div class="row g-2">
                <div class="col-md-6"><?php echo $__env->make('agency.products._qv-quill-inline', ['name' => 'inclusions', 'label' => 'Fiyata Dahil', 'value' => $tour->inclusions, 'uf' => $uf, 'defs' => $inclusionsTemplates ?? null, 'defsMode' => 'block', 'defsLabel' => 'Hazır tanım ekle', 'defsIcon' => 'fa-circle-check'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?></div>
                <div class="col-md-6"><?php echo $__env->make('agency.products._qv-quill-inline', ['name' => 'exclusions', 'label' => 'Fiyata Dahil Değil', 'value' => $tour->exclusions, 'uf' => $uf, 'defs' => $exclusionsTemplates ?? null, 'defsMode' => 'block', 'defsLabel' => 'Hazır tanım ekle', 'defsIcon' => 'fa-circle-xmark'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?></div>
            </div>
        </div>
    </div>

    <?php if($isDay): ?>
        
        <div class="pfx">
            <div class="pfx-top">
                <span class="pfx-top-t"><i class="fas fa-map-location-dot"></i> Kalkış Noktaları</span>
            </div>
            <div class="pfx-body" data-qv-transfer-save="<?php echo e($transferUrl); ?>">
                <?php echo $__env->make('agency.products._qv-departure-points', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
            </div>
        </div>
    <?php else: ?>
        
        <?php
            $isAir = $tour->transportation_method === 'air';
            $isRoad = in_array($tour->transportation_method, ['road', 'train', 'ferry', 'other']);
            $airRows = [
                $row('Kalkış Havalimanı', 'departure_airports', $tour->departure_airports),
                $row('Varış Havalimanı', 'arrival_airports', $tour->arrival_airports),
                $row('Uçuş Numarası', 'departure_flight_number', $tour->departure_flight_number, null, ['mono' => true]),
                $row('Uçuş Kalkış Saati', 'flight_departure_time', $flightTime, $flightTime, ['type' => 'time', 'mono' => true]),
            ];
        ?>
        <div class="pfx show-empty pfx-lw" data-url="<?php echo e($uf); ?>">
            <div class="pfx-top">
                <span class="pfx-top-t"><i class="fas fa-route"></i> Ulaşım</span>
            </div>
            <section class="pfx-sec">
                <?php echo $__env->make('components.quick-view.ledger-row', ['r' => $row('Ulaşım Şekli', 'transportation_method', $tour->transportation_method, $optLabel($transportOptions, $tour->transportation_method), ['type' => 'select', 'options' => $transportOptions, 'ph' => 'Ulaşım şekli seçin'])], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
            </section>

            
            <div class="qg-air" style="<?php echo e($isAir ? '' : 'display:none'); ?>">
                <section class="pfx-sec">
                    <div class="pfx-sec-h">
                        <i class="fas fa-plane"></i>
                        <span>Uçuş Bilgileri</span>
                        <button type="button" class="pfx-secopy" data-a="copy-sec" title="Bu bölümü kopyala"><i class="fas fa-copy"></i></button>
                    </div>
                    <?php $__currentLoopData = $airRows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $r): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php echo $__env->make('components.quick-view.ledger-row', ['r' => $r], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </section>
            </div>

            
            <div class="qg-road" data-qv-transfer-save="<?php echo e($transferUrl); ?>" style="<?php echo e($isRoad ? '' : 'display:none'); ?>">
                <div class="pfx-body">
                    <?php echo $__env->make('agency.products._qv-departure-points', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                </div>
            </div>

            <section class="pfx-sec">
                <?php echo $__env->make('components.quick-view.ledger-row', ['r' => $row('Ulaşım Notları', 'transportation_notes', $tour->transportation_notes, null, ['type' => 'textarea', 'ph' => 'Ulaşımla ilgili not'])], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
            </section>
        </div>
    <?php endif; ?>

    
    <div class="pfx">
        <div class="pfx-top">
            <span class="pfx-top-t"><i class="fas fa-file-contract"></i> Politikalar</span>
        </div>
        <div class="pfx-body">
            <div class="mb-2">
                <?php echo $__env->make('agency.products._qv-hours-unit-field', ['field' => 'cancellation_deadline_hours', 'label' => 'Ücretsiz İptal (kalkıştan önce)', 'hours' => $tour->cancellation_deadline_hours, 'uf' => $uf], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
            </div>
            <?php echo $__env->make('agency.products._qv-quill-inline', ['name' => 'cancellation_policy', 'label' => 'İptal Politikası', 'value' => $tour->cancellation_policy, 'uf' => $uf, 'defs' => $cancellationPolicies ?? null, 'defsMode' => 'block', 'defsLabel' => 'Hazır iptal koşulu', 'defsIcon' => 'fa-ban'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
            <?php echo $__env->make('agency.products._qv-quill-inline', ['name' => 'terms_conditions', 'label' => 'Şartlar & Koşullar', 'value' => $tour->terms_conditions, 'uf' => $uf, 'defs' => $termsConditions ?? null, 'defsMode' => 'block', 'defsLabel' => 'Hazır şart metni', 'defsIcon' => 'fa-file-contract'], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
        </div>
    </div>

    
    <?php
        $ptSlug = ['cultural' => 'kultur-turu', 'international' => 'yurtdisi-turu', 'day' => 'gunubirlik-tur'][$productType] ?? 'gunubirlik-tur';
        $ptId = \App\Models\Product\ProductType::where('slug', $ptSlug)->value('id');
    ?>
    <div class="pfx">
        <div class="pfx-top">
            <span class="pfx-top-t"><i class="fas fa-tags"></i> Kategoriler</span>
        </div>
        <div class="pfx-body">
            
            <div class="qcat-cloud" data-qv-cat-save="<?php echo e($catUrl); ?>">
                <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <label class="qcat-chip">
                        <input type="checkbox" value="<?php echo e($cat->id); ?>" <?php if(in_array($cat->id, $selectedCatIds)): echo 'checked'; endif; ?>>
                        <span class="qcat-face"><i class="fas fa-check"></i><span><?php echo e($cat->name); ?></span></span>
                    </label>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>
            <?php if(!$categories->count()): ?>
                <p class="qcat-empty text-muted">Tanımlı kategori yok. Aşağıdan hızlıca ekleyebilirsiniz.</p>
            <?php endif; ?>
            
            <div class="qv-cat-add" data-qv-cat-add data-store-url="<?php echo e(route('agency.categories.store')); ?>" data-product-type="<?php echo e($ptId); ?>">
                <i class="fas fa-tag"></i>
                <input type="text" placeholder="Yeni kategori ekle…" maxlength="255">
                <button type="button"><i class="fas fa-plus"></i>Ekle</button>
            </div>
        </div>
    </div>
</div>


<?php echo $__env->make('components.quick-view.ledger-ui', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

<?php if (! ($isDay)): ?>
<script>
(function () {
    if (window.__qgLedgerTransport) return;
    window.__qgLedgerTransport = true;

    // Ulaşım Şekli ledger satırından değişince uçak/karayolu bloklarını aç-kapa.
    // ledger-ui düzenleme kontrolüne data-field yazar; change kaydetmeden önce
    // burada da yakalanır (kayıt ledger-ui'nin kendi change dinleyicisinde).
    document.addEventListener('change', function (e) {
        var ctl = e.target.closest('select.pfx-in[data-field="transportation_method"]');
        if (!ctl) return;
        var form = ctl.closest('.qv-gform');
        if (!form) return;
        var v = ctl.value;
        form.querySelectorAll('.qg-air').forEach(function (x) { x.style.display = v === 'air' ? '' : 'none'; });
        form.querySelectorAll('.qg-road').forEach(function (x) { x.style.display = ['road', 'train', 'ferry', 'other'].indexOf(v) !== -1 ? '' : 'none'; });
    });
})();
</script>
<?php endif; ?>
<?php /**PATH C:\xampp\htdocs\acente\resources\views/agency/products/_qv-general-ledger.blade.php ENDPATH**/ ?>