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

<?php
    $docs = $customer->customerDocuments->sortByDesc('created_at');
    $today = \Carbon\Carbon::today();

    $fmtSize = function ($bytes) {
        $bytes = (int) $bytes;
        if ($bytes <= 0) return '—';
        $u = ['B', 'KB', 'MB', 'GB'];
        $i = (int) floor(log($bytes, 1024));
        $i = min($i, count($u) - 1);
        return round($bytes / (1024 ** $i), $i ? 1 : 0) . ' ' . $u[$i];
    };
    $iconFor = function ($mime, $name) {
        $ext = strtolower(pathinfo((string) $name, PATHINFO_EXTENSION));
        return match (true) {
            str_contains((string) $mime, 'pdf') || $ext === 'pdf' => ['fa-file-pdf', '#dc2626'],
            str_contains((string) $mime, 'image') || in_array($ext, ['jpg','jpeg','png','webp','gif']) => ['fa-file-image', '#0ea5e9'],
            in_array($ext, ['xls','xlsx','csv']) => ['fa-file-excel', '#16a34a'],
            in_array($ext, ['doc','docx']) => ['fa-file-word', '#2563eb'],
            in_array($ext, ['zip','rar','7z']) => ['fa-file-zipper', '#a855f7'],
            default => ['fa-file-lines', '#64748b'],
        };
    };
?>

<div class="cdx-wrap">

    
    <form id="ajax-doc-upload" class="cdx-drop" method="POST"
          action="<?php echo e(route('agency.customers.documents.store', $customer)); ?>" enctype="multipart/form-data">
        <?php echo csrf_field(); ?>
        <div class="cdx-drop-inner" id="cdxDrop">
            <div class="cdx-drop-ico"><i class="fas fa-cloud-arrow-up"></i></div>
            <div class="cdx-drop-txt">
                <b>Dosyayı buraya sürükleyin</b>
                <span>ya da <button type="button" class="cdx-browse" onclick="document.getElementById('cdxFile').click()">bilgisayardan seçin</button></span>
            </div>
            <input type="file" name="file" id="cdxFile" hidden required onchange="cdxPick(this)">
        </div>

        <div class="cdx-drop-row">
            <div class="cdx-fld">
                <label>Belge Tipi <span>*</span></label>
                <select name="document_type_id" required>
                    <option value="">Tip seçin…</option>
                    <?php $__currentLoopData = $documentTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($type->id); ?>"><?php echo e($type->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="cdx-picked" id="cdxPicked" hidden>
                <i class="fas fa-paperclip"></i><span id="cdxPickedName">—</span>
                <button type="button" class="cdx-clear" onclick="cdxClear()"><i class="fas fa-xmark"></i></button>
            </div>
            <button type="submit" class="cdx-up-btn"><i class="fas fa-upload me-1"></i> Yükle</button>
        </div>
    </form>

    
    
    <?php $opDocs = $customer->passengerDocuments->sortByDesc('created_at'); ?>
    <?php if($opDocs->count()): ?>
        <div class="qvt-bar">
            <span class="qvt-bar-info"><i class="fas fa-diagram-project"></i> Operasyondan üretilenler (<?php echo e($opDocs->count()); ?>)</span>
        </div>

        <div class="qvt-box">
            <div class="qvt-scroll">
                <table class="qvt">
                    <thead>
                        <tr>
                            <th>Belge</th>
                            <th>Tür</th>
                            <th>Yolcu</th>
                            <th>Satış</th>
                            <th>Tarih</th>
                            <th>Durum</th>
                            <th class="qvt-w1"></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $opDocs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $od): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php
                                // departure_type FQCN saklar (ör. Tour\TourDate) → operasyon URL tip anahtarına çevrilir
                                $odOpKey = $od->departure_type
                                    ? (\App\Services\Operation\OperationService::TYPE_META[$od->departure_type]['key'] ?? null)
                                    : null;
                            ?>
                            <tr>
                                <td class="qvt-trunc" title="<?php echo e($od->title); ?>">
                                    <i class="fas fa-file-signature qvt-dim"></i>
                                    <span class="qvt-c qvt-strong" data-copy="<?php echo e($od->title); ?>"><?php echo e($od->title); ?></span>
                                </td>
                                <td><span class="qvt-chip"><?php echo e($od->kind_label); ?></span></td>
                                <td class="qvt-trunc" title="<?php echo e($od->passenger?->full_name); ?>"><?php echo e($od->passenger?->full_name ?: '—'); ?></td>
                                <td class="qvt-nowrap">
                                    <?php if($od->sale): ?>
                                        <span class="qvt-link" title="Satış kartını aç" onclick="openSaleDrawer(<?php echo e($od->sale_id); ?>)">#<?php echo e($od->sale->sale_code); ?></span>
                                    <?php endif; ?>
                                    <?php if($odOpKey && $od->departure_id): ?>
                                        <span class="qvt-link" title="Operasyon kartını aç"
                                              onclick="openQuickView('<?php echo e(route('agency.operations.quick-view', [$odOpKey, $od->departure_id])); ?>')">
                                            <i class="fas fa-diagram-project"></i>
                                        </span>
                                    <?php endif; ?>
                                    <?php if(!$od->sale && !($odOpKey && $od->departure_id)): ?><span class="qvt-none">—</span><?php endif; ?>
                                </td>
                                <td class="qvt-mono qvt-nowrap"><?php echo e($od->created_at->format('d.m.Y')); ?></td>
                                <td><span class="qvt-badge" style="--sc:<?php echo e($od->status_color); ?>"><?php echo e($od->status_label); ?></span></td>
                                <td class="qvt-w1">
                                    <a class="qvt-act" href="<?php echo e(route('agency.passenger-documents.pdf', $od)); ?>" target="_blank" title="PDF indir"><i class="fas fa-file-pdf"></i></a>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        </div>

        <div class="cdx-opnote">
            <i class="fas fa-circle-info"></i>
            Bu belgeler operasyon yolcu listesinden üretildi. Düzenleme ilgili kalkışın operasyon kartından yapılır.
        </div>
    <?php endif; ?>

    
    <div class="qvt-bar">
        <span class="qvt-bar-info">
            <i class="fas fa-folder-open"></i>
            <?php echo e($docs->count()); ?> yüklenen belge
            <?php if($docs->count()): ?> · <?php echo e($fmtSize($docs->sum('file_size'))); ?> toplam <?php endif; ?>
        </span>
    </div>

    <div class="qvt-box">
        <div class="qvt-scroll">
            <table class="qvt">
                <thead>
                    <tr>
                        <th>Dosya</th>
                        <th>Tip</th>
                        <th class="ta-r">Boyut</th>
                        <th>Yüklendi</th>
                        <th>Geçerlilik</th>
                        <th>Not</th>
                        <th class="qvt-w1"></th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $docs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $doc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            [$icon, $color] = $iconFor($doc->mime_type, $doc->file_name);
                            $exp = $doc->expiry_date ? \Carbon\Carbon::parse($doc->expiry_date) : null;
                            $expState = !$exp ? null : ($exp->lt($today) ? 'expired' : ($exp->lte($today->copy()->addMonth()) ? 'soon' : null));
                            $fileUrl = asset('storage/' . $doc->file_path);
                        ?>
                        <tr class="<?php echo e($expState === 'expired' ? 'is-muted' : ''); ?>">
                            <td class="qvt-trunc" title="<?php echo e($doc->file_name); ?>">
                                <i class="fas <?php echo e($icon); ?>" style="color:<?php echo e($color); ?>"></i>
                                <span class="qvt-c qvt-strong" data-copy="<?php echo e($doc->file_name); ?>"><?php echo e($doc->file_name); ?></span>
                            </td>
                            <td><span class="qvt-chip"><?php echo e($doc->type?->name ?: 'Diğer'); ?></span></td>
                            <td class="ta-r qvt-mono qvt-dim"><?php echo e($fmtSize($doc->file_size)); ?></td>
                            <td class="qvt-mono qvt-nowrap"><?php echo e($doc->created_at->format('d.m.Y')); ?></td>
                            <td class="qvt-nowrap">
                                <?php if($exp): ?>
                                    <span class="qvt-chip <?php echo e($expState === 'expired' ? 'danger' : ($expState === 'soon' ? 'warn' : '')); ?>">
                                        <?php if($expState): ?><i class="fas <?php echo e($expState === 'expired' ? 'fa-triangle-exclamation' : 'fa-clock'); ?>"></i><?php endif; ?>
                                        <?php echo e($exp->format('d.m.Y')); ?>

                                    </span>
                                <?php else: ?>
                                    <span class="qvt-none">—</span>
                                <?php endif; ?>
                            </td>
                            <td class="qvt-trunc qvt-dim" title="<?php echo e($doc->notes); ?>"><?php echo e($doc->notes ?: '—'); ?></td>
                            <td class="qvt-w1">
                                <a class="qvt-act" href="<?php echo e($fileUrl); ?>" target="_blank" title="Görüntüle"><i class="fas fa-eye"></i></a>
                                <a class="qvt-act" href="<?php echo e($fileUrl); ?>" download title="İndir"><i class="fas fa-download"></i></a>
                                <button type="button" class="qvt-copyall" data-copy="<?php echo e($fileUrl); ?>" title="Bağlantıyı kopyala"><i class="fas fa-link"></i></button>
                                <button type="button" class="qvt-act danger" title="Sil" onclick="deleteDocument(<?php echo e($doc->id); ?>, this)"><i class="fas fa-trash"></i></button>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr class="qvt-empty">
                            <td colspan="7">
                                <i class="fas fa-folder-open"></i>
                                <b>Henüz belge yüklenmemiş</b>
                                <span>Pasaport, kimlik, vize, sözleşme gibi belgeleri buraya yükleyin.</span>
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<?php /**PATH C:\xampp\htdocs\acente\resources\views/agency/customers/partials/qv-documents.blade.php ENDPATH**/ ?>