
<?php echo $__env->make('agency.partials.qv-table', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

<?php
    $today = \Carbon\Carbon::today();
    $genderOpts = [['value' => '', 'label' => '—'], ['value' => 'male', 'label' => 'Erkek'], ['value' => 'female', 'label' => 'Kadın'], ['value' => 'other', 'label' => 'Diğer']];
    $genderLabel = fn ($v) => collect($genderOpts)->firstWhere('value', (string) $v)['label'] ?? '';

    $dmy = fn ($d) => $d ? \Carbon\Carbon::parse($d)->format('d.m.Y') : '';
    $iso = fn ($d) => $d ? \Carbon\Carbon::parse($d)->format('Y-m-d') : '';

    /** Yolcu satırı: [etiket, alan, ham değer, görünen metin, seçenekler] */
    $prow = fn (string $label, ?string $field, $value, ?string $text = null, array $o = []) => [
        'label' => $label,
        'field' => $field,
        'type' => $o['type'] ?? 'text',
        'value' => $value === null ? '' : (string) $value,
        'text' => $text === null ? (string) ($value ?? '') : $text,
        'options' => $o['options'] ?? null,
        'mono' => $o['mono'] ?? false,
        'ph' => $o['ph'] ?? null,
        'state' => $o['state'] ?? null,
    ];
?>

<div class="cpx-wrap">

    
    <div class="cpx-bar">
        <div class="cpx-bar-stats">
            <span class="cpx-stat"><i class="fas fa-users"></i><b><?php echo e($customer->passengers->count()); ?></b> yolcu</span>
            <?php
                $missingId = $customer->passengers->filter(fn($p) => !$p->national_id && !$p->passport_number)->count();
                $expiring = $customer->passengers->filter(function ($p) use ($today) {
                    $d = $p->passport_expiry ? \Carbon\Carbon::parse($p->passport_expiry) : null;
                    return $d && $d->lte($today->copy()->addMonths(6));
                })->count();
            ?>
            <?php if($missingId): ?>
                <span class="cpx-sep"></span>
                <span class="cpx-stat warn" title="Kimlik veya pasaport bilgisi girilmemiş"><i class="fas fa-id-card"></i><b><?php echo e($missingId); ?></b> kimliksiz</span>
            <?php endif; ?>
            <?php if($expiring): ?>
                <span class="cpx-sep"></span>
                <span class="cpx-stat danger" title="Pasaportu 6 ay içinde dolacak / dolmuş"><i class="fas fa-passport"></i><b><?php echo e($expiring); ?></b> pasaport uyarısı</span>
            <?php endif; ?>
        </div>
        <div class="cpx-bar-actions">
            <?php if($customer->passengers->count() > 3): ?>
                <div class="cpx-search">
                    <i class="fas fa-magnifying-glass"></i>
                    <input type="text" placeholder="Yolcu ara…" oninput="cpxFilter(this.value)">
                </div>
            <?php endif; ?>
            <button type="button" class="cpx-add-btn" onclick="cpxToggleNew()">
                <i class="fas fa-user-plus"></i> Yolcu Ekle
            </button>
        </div>
    </div>

    
    <form id="cpxNewForm" class="cpx-new" hidden method="POST"
          action="<?php echo e(route('agency.customers.passengers.store', $customer)); ?>">
        <?php echo csrf_field(); ?>
        <div class="cpx-new-head"><i class="fas fa-user-plus"></i> Yeni Yolcu</div>
        <div class="cpx-new-grid">
            <div class="cpx-fld"><label>Ad <span>*</span></label><input type="text" name="first_name" required></div>
            <div class="cpx-fld"><label>Soyad <span>*</span></label><input type="text" name="last_name" required></div>
            <div class="cpx-fld"><label>Yakınlık</label><input type="text" name="relationship" placeholder="Eş, çocuk…"></div>
            <div class="cpx-fld"><label>Cinsiyet</label>
                <select name="gender"><?php $__currentLoopData = $genderOpts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $o): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($o['value']); ?>"><?php echo e($o['label']); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
            </div>
            <div class="cpx-fld"><label>Doğum Tarihi</label><input type="date" name="birth_date"></div>
            <div class="cpx-fld"><label>T.C. Kimlik No</label><input type="text" name="national_id" maxlength="20"></div>
            <div class="cpx-fld"><label>Telefon</label><input type="text" name="phone" maxlength="20"></div>
            <div class="cpx-fld"><label>E-posta</label><input type="email" name="email"></div>
        </div>
        <div class="cpx-new-foot">
            <button type="button" class="cpx-cancel" onclick="cpxToggleNew()">Vazgeç</button>
            <button type="submit" class="cpx-save"><i class="fas fa-check me-1"></i>Yolcuyu Ekle</button>
        </div>
    </form>

    
    <div class="qvt-box">
        <div class="qvt-scroll">
            <table class="qvt" id="cpxList">
                <thead>
                    <tr>
                        <th>Yolcu</th>
                        <th>Yakınlık</th>
                        <th>Doğum</th>
                        <th>Cinsiyet</th>
                        <th>T.C. Kimlik</th>
                        <th>Pasaport</th>
                        <th>Geçerlilik</th>
                        <th>Telefon</th>
                        <th>E-posta</th>
                        <th class="qvt-w1"></th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $customer->passengers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            $url = route('agency.customers.passengers.update-field', [$customer, $p]);
                            $birth = $p->birth_date ? \Carbon\Carbon::parse($p->birth_date) : null;
                            // Carbon 3'te diffInYears ondalıklı döner (17.55 gibi)
                            $age = $birth ? (int) $birth->diffInYears($today) : null;
                            $ppExpiry = $p->passport_expiry ? \Carbon\Carbon::parse($p->passport_expiry) : null;
                            $ppState = !$ppExpiry ? null : ($ppExpiry->lt($today) ? 'expired' : ($ppExpiry->lte($today->copy()->addMonths(6)) ? 'soon' : null));
                            $vsExpiry = $p->visa_expiry ? \Carbon\Carbon::parse($p->visa_expiry) : null;
                            $vsState = !$vsExpiry ? null : ($vsExpiry->lt($today) ? 'expired' : ($vsExpiry->lte($today->copy()->addMonth()) ? 'soon' : null));

                            $pSections = [
                                ['title' => 'Kimlik', 'icon' => 'fa-id-badge', 'rows' => [
                                    $prow('Ad', 'first_name', $p->first_name),
                                    $prow('Soyad', 'last_name', $p->last_name),
                                    $prow('T.C. Kimlik No', 'national_id', $p->national_id, null, ['mono' => true, 'ph' => '11 hane']),
                                    $prow('Doğum Tarihi', 'birth_date', $iso($p->birth_date), $dmy($p->birth_date), ['type' => 'date', 'mono' => true]),
                                    $prow('Cinsiyet', 'gender', $p->gender, $genderLabel($p->gender), ['type' => 'select', 'options' => $genderOpts]),
                                    $prow('Yakınlık', 'relationship', $p->relationship, null, ['ph' => 'Eş, çocuk, arkadaş…']),
                                ]],
                                ['title' => 'Seyahat Belgeleri', 'icon' => 'fa-passport', 'rows' => [
                                    $prow('Pasaport No', 'passport_number', $p->passport_number, null, ['mono' => true]),
                                    $prow('Pasaport Geçerlilik', 'passport_expiry', $iso($p->passport_expiry), $dmy($p->passport_expiry), ['type' => 'date', 'mono' => true, 'state' => $ppState]),
                                    $prow('Vize Durumu', 'visa_status', $p->visa_status, null, ['ph' => 'Örn: Schengen']),
                                    $prow('Vize Bitiş', 'visa_expiry', $iso($p->visa_expiry), $dmy($p->visa_expiry), ['type' => 'date', 'mono' => true, 'state' => $vsState]),
                                ]],
                                ['title' => 'İletişim', 'icon' => 'fa-address-book', 'rows' => [
                                    $prow('Telefon', 'phone', $p->phone, null, ['mono' => true, 'ph' => '05xx xxx xx xx']),
                                    $prow('E-posta', 'email', $p->email, null, ['type' => 'email', 'ph' => 'ornek@eposta.com']),
                                ]],
                            ];

                            $pEmpty = collect($pSections)->flatMap(fn ($s) => $s['rows'])->filter(fn ($r) => blank($r['text']))->count();

                            // Satır sonundaki "tümünü kopyala": dolu alanlar "Etiket: değer" olarak
                            $copyAll = collect($pSections)
                                ->flatMap(fn ($s) => $s['rows'])
                                ->filter(fn ($r) => filled($r['text']))
                                ->map(fn ($r) => $r['label'] . ': ' . $r['text'])
                                ->implode("\n");
                        ?>

                        <tr class="cpx-tr" data-cpx-id="<?php echo e($p->id); ?>" data-cpx-name="<?php echo e(mb_strtolower($p->full_name)); ?>">
                            <td class="qvt-nowrap">
                                <span class="cpx-av"><?php echo e($p->initials); ?></span>
                                <span class="qvt-c qvt-strong" data-copy="<?php echo e($p->full_name); ?>" data-role="cpx-row-name"><?php echo e($p->full_name ?: 'İsimsiz yolcu'); ?></span>
                                <?php if($ppState === 'expired'): ?><span class="qvt-chip danger" title="Pasaport süresi dolmuş"><i class="fas fa-triangle-exclamation"></i></span>
                                <?php elseif($ppState === 'soon'): ?><span class="qvt-chip warn" title="Pasaport <?php echo e((int) $today->diffInDays($ppExpiry)); ?> gün içinde doluyor"><i class="fas fa-clock"></i></span><?php endif; ?>
                                <?php if($vsState === 'expired'): ?><span class="qvt-chip danger" title="Vize süresi dolmuş">vize</span><?php endif; ?>
                            </td>
                            <td><?php echo e($p->relationship ?: '—'); ?></td>
                            <td class="qvt-mono qvt-nowrap">
                                <?php if($birth): ?><?php echo e($dmy($p->birth_date)); ?> <span class="qvt-dim">(<?php echo e($age); ?>)</span><?php else: ?><span class="qvt-none">—</span><?php endif; ?>
                            </td>
                            <td><?php echo e($genderLabel($p->gender) ?: '—'); ?></td>
                            <td class="qvt-nowrap">
                                <?php if($p->national_id): ?><span class="qvt-c qvt-mono" data-copy="<?php echo e($p->national_id); ?>"><?php echo e($p->national_id); ?></span><?php else: ?><span class="qvt-none">—</span><?php endif; ?>
                            </td>
                            <td class="qvt-nowrap">
                                <?php if($p->passport_number): ?><span class="qvt-c qvt-mono" data-copy="<?php echo e($p->passport_number); ?>"><?php echo e($p->passport_number); ?></span><?php else: ?><span class="qvt-none">—</span><?php endif; ?>
                            </td>
                            <td class="qvt-nowrap">
                                <?php if($ppExpiry): ?>
                                    <span class="qvt-chip <?php echo e($ppState === 'expired' ? 'danger' : ($ppState === 'soon' ? 'warn' : '')); ?>"><?php echo e($ppExpiry->format('d.m.Y')); ?></span>
                                <?php else: ?>
                                    <span class="qvt-none">—</span>
                                <?php endif; ?>
                            </td>
                            <td class="qvt-nowrap">
                                <?php if($p->phone): ?><span class="qvt-c qvt-mono" data-copy="<?php echo e($p->phone); ?>"><?php echo e($p->phone); ?></span><?php else: ?><span class="qvt-none">—</span><?php endif; ?>
                            </td>
                            <td class="qvt-trunc" title="<?php echo e($p->email); ?>">
                                <?php if($p->email): ?><span class="qvt-c" data-copy="<?php echo e($p->email); ?>"><?php echo e($p->email); ?></span><?php else: ?><span class="qvt-none">—</span><?php endif; ?>
                            </td>
                            <td class="qvt-w1">
                                <button type="button" class="qvt-copyall" data-copy="<?php echo e($copyAll); ?>" title="Yolcunun tüm bilgilerini kopyala">
                                    <i class="fas fa-clone"></i>
                                </button>
                                <button type="button" class="qvt-act cpx-toggle" onclick="cpxToggleRow(this)" title="Detay / düzenle">
                                    <i class="fas fa-chevron-down"></i>
                                </button>
                                <button type="button" class="qvt-act danger" title="Yolcuyu sil"
                                        onclick="cpxDelete('<?php echo e(route('agency.customers.passengers.destroy', [$customer, $p])); ?>', this, <?php echo \Illuminate\Support\Js::from($p->full_name)->toHtml() ?>)">
                                    <i class="fas fa-trash"></i>
                                </button>
                            </td>
                        </tr>

                        
                        <tr class="cpx-det" hidden>
                            <td colspan="10">
                                <div class="pfx cpx-card show-empty" data-url="<?php echo e($url); ?>"
                                     data-cpx-id="<?php echo e($p->id); ?>" data-cpx-name="<?php echo e(mb_strtolower($p->full_name)); ?>">

                                    <div class="pfx-top cpx-head">
                                        <span class="cpx-av"><?php echo e($p->initials); ?></span>
                                        <span class="cpx-idn">
                                            <b data-role="pfx-name"><?php echo e($p->full_name ?: 'İsimsiz yolcu'); ?></b>
                                            <small>
                                                <?php if($age !== null): ?><span class="cpx-chip"><?php echo e($age); ?> yaş</span><?php endif; ?>
                                                <?php if($p->relationship): ?><span class="cpx-chip soft"><?php echo e($p->relationship); ?></span><?php endif; ?>
                                            </small>
                                        </span>
                                        <button type="button" class="pfx-chip" data-a="empties" title="Doldurulmamış alanları göster / gizle">
                                            <i class="fas fa-eye-slash"></i> <span data-role="empties-n"><?php echo e($pEmpty); ?></span> boş
                                        </button>
                                        <button type="button" class="pfx-chip" data-a="copy-all" title="Yolcunun tüm bilgilerini kopyala">
                                            <i class="fas fa-clone"></i> Tümü
                                        </button>
                                    </div>

                                    <div class="cpx-body">
                                        <?php $__currentLoopData = $pSections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sec): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <section class="pfx-sec">
                                                <div class="pfx-sec-h">
                                                    <i class="fas <?php echo e($sec['icon']); ?>"></i>
                                                    <span><?php echo e($sec['title']); ?></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 = $sec['rows']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $r): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php $shown = trim((string) $r['text']); ?>
                                                    <div class="pfx-row <?php echo e($r['mono'] ? 'mono' : ''); ?> <?php echo e($r['state'] ? 'st-' . $r['state'] : ''); ?>"
                                                         data-field="<?php echo e($r['field']); ?>"
                                                         data-type="<?php echo e($r['type']); ?>"
                                                         data-value="<?php echo e($r['value']); ?>"
                                                         data-label="<?php echo e($r['label']); ?>"
                                                         <?php if($r['options']): ?> data-options='<?php echo json_encode($r['options'], 15, 512) ?>' <?php endif; ?>
                                                         <?php if($shown === ''): ?> data-empty="1" <?php endif; ?>>
                                                        <span class="pfx-l">
                                                            <?php echo e($r['label']); ?>

                                                            <?php if($r['state'] === 'expired'): ?><b class="pfx-flag danger">dolmuş</b>
                                                            <?php elseif($r['state'] === 'soon'): ?><b class="pfx-flag warn">yakın</b><?php endif; ?>
                                                        </span>
                                                        <span class="pfx-v" data-ph="<?php echo e($r['ph'] ?: '—'); ?>" title="<?php echo e($shown); ?>"><?php echo e($shown); ?></span>
                                                        <span class="pfx-a">
                                                            <button type="button" class="pfx-b" data-a="copy" tabindex="-1" title="Kopyala"><i class="fas fa-copy"></i></button>
                                                            <button type="button" class="pfx-b" data-a="edit" tabindex="-1" title="Düzenle"><i class="fas fa-pen"></i></button>
                                                        </span>
                                                    </div>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </section>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr class="qvt-empty">
                            <td colspan="10">
                                <i class="fas fa-user-slash"></i>
                                <b>Henüz yolcu kaydı yok</b>
                                <span>Bu müşteriye bağlı kişileri ekleyin — satışlarda ve operasyon yolcu listesinde hazır gelir.</span>
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>

    <div class="cpx-foot">
        <i class="fas fa-copy"></i> Bir değerin üzerine gelip sağdaki simgeyle kopyalayın.
        <span class="cpx-foot-sep"></span>
        <i class="fas fa-chevron-down"></i> Detay düğmesiyle açılan alanlar yerinde düzenlenir.
    </div>
</div>
<?php /**PATH C:\xampp\htdocs\acente\resources\views/agency/customers/partials/qv-passengers.blade.php ENDPATH**/ ?>