<?php $__env->startSection('title', 'Customer Document Vault'); ?>

<?php $__env->startSection('content'); ?>
<div class="space-y-5">
    <?php echo $__env->make('tenant.partials.typist-page-nav', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

    <section class="rounded-[28px] border border-violet-100 bg-gradient-to-br from-white via-violet-50 to-sky-50 p-6 shadow-sm sm:p-8">
        <div class="flex flex-col gap-5 lg:flex-row lg:items-end lg:justify-between">
            <div><span class="text-[11px] font-bold uppercase tracking-[0.18em] text-violet-700">Secure customer records</span><h1 class="mt-2 text-2xl font-bold tracking-tight text-slate-950 sm:text-3xl">Document vault</h1><p class="mt-2 max-w-2xl text-sm text-slate-600">Find passports, Emirates IDs, visas and certificates, then act before expiry interrupts a service.</p></div>
            <div class="flex gap-2"><a href="<?php echo e(route('app.renewals.index')); ?>" class="rounded-xl border border-violet-200 bg-white px-4 py-2.5 text-xs font-bold text-violet-700 shadow-sm">Renewal center</a><a href="<?php echo e(route('app.customers.index')); ?>" class="rounded-xl bg-slate-900 px-4 py-2.5 text-xs font-bold text-white">Open customers</a></div>
        </div>
    </section>

    <section class="grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
        <?php $__currentLoopData = [
            ['Current documents', $metrics['total'], 'bg-violet-100 text-violet-700'],
            ['Valid beyond 60 days', $metrics['valid'], 'bg-emerald-100 text-emerald-700'],
            ['Expiring in 60 days', $metrics['expiring'], 'bg-orange-100 text-orange-700'],
            ['Expired', $metrics['expired'], 'bg-red-100 text-red-700'],
        ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$label, $value, $tone]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <article class="rounded-2xl border border-slate-200 bg-white p-4 shadow-sm"><div class="flex items-center justify-between"><span class="text-xs font-bold text-slate-600"><?php echo e($label); ?></span><span class="grid h-9 w-9 place-items-center rounded-xl <?php echo e($tone); ?>">◆</span></div><strong class="mt-4 block text-2xl text-slate-950"><?php echo e(number_format($value)); ?></strong></article>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </section>

    <form method="GET" class="grid gap-3 rounded-3xl border border-slate-200 bg-white p-4 shadow-sm md:grid-cols-[minmax(0,1fr)_220px_auto]">
        <input name="q" value="<?php echo e(request('q')); ?>" class="rounded-xl border-slate-200 bg-slate-50 px-4 py-2.5 text-xs focus:border-violet-400 focus:ring-violet-200" placeholder="Search customer, document or number">
        <select name="expiry" class="rounded-xl border-slate-200 bg-slate-50 px-3 py-2.5 text-xs"><option value="">Any expiry status</option><option value="valid" <?php if(request('expiry') === 'valid'): echo 'selected'; endif; ?>>Valid</option><option value="expiring" <?php if(request('expiry') === 'expiring'): echo 'selected'; endif; ?>>Expiring in 60 days</option><option value="expired" <?php if(request('expiry') === 'expired'): echo 'selected'; endif; ?>>Expired</option></select>
        <div class="flex gap-2"><button class="rounded-xl bg-slate-900 px-5 py-2.5 text-xs font-bold text-white">Search vault</button><a href="<?php echo e(route('app.customers.documents.index')); ?>" class="rounded-xl border border-slate-200 px-3 py-2.5 text-xs font-bold text-slate-500">Reset</a></div>
    </form>

    <section class="overflow-hidden rounded-3xl border border-slate-200 bg-white shadow-sm">
        <div class="overflow-x-auto">
            <table class="w-full min-w-[950px] text-left text-xs">
                <thead class="border-b border-slate-200 bg-slate-50 text-[10px] font-bold uppercase tracking-wider text-slate-500"><tr><th class="px-5 py-4">Customer</th><th class="px-5 py-4">Document</th><th class="px-5 py-4">Number</th><th class="px-5 py-4">Expiry</th><th class="px-5 py-4">Health</th><th class="px-5 py-4">Version</th><th class="px-5 py-4 text-right">Secure file</th></tr></thead>
                <tbody class="divide-y divide-slate-100">
                    <?php $__empty_1 = true; $__currentLoopData = $documents; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $document): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            $expired = $document->expiry_date && $document->expiry_date->isPast();
                            $expiring = !$expired && $document->expiry_date && $document->expiry_date->lte(today()->addDays(60));
                            $healthLabel = $expired ? 'Expired' : ($expiring ? 'Expiring soon' : 'Valid');
                            $healthTone = $expired ? 'bg-red-100 text-red-700' : ($expiring ? 'bg-orange-100 text-orange-700' : 'bg-emerald-100 text-emerald-700');
                        ?>
                        <tr class="hover:bg-violet-50/40">
                            <td class="px-5 py-4"><a href="<?php echo e(route('app.customers.show', $document->customer_id)); ?>" class="font-bold text-slate-900 hover:text-violet-700"><?php echo e($document->customer?->full_name_en ?? 'Customer unavailable'); ?></a><span class="mt-1 block text-[10px] text-slate-400"><?php echo e($document->customer?->customer_code); ?> · <?php echo e($document->customer?->contact?->primary_mobile ?? 'No mobile'); ?></span></td>
                            <td class="px-5 py-4"><strong class="block text-slate-800"><?php echo e($document->document_name); ?></strong><span class="mt-1 block text-[10px] text-slate-400"><?php echo e($document->documentType?->name_en ?? 'Customer document'); ?></span></td>
                            <td class="px-5 py-4 font-mono text-slate-600"><?php echo e($document->document_number ?: 'Not recorded'); ?></td>
                            <td class="px-5 py-4"><strong class="block text-slate-800"><?php echo e($document->expiry_date?->format('d M Y') ?? 'No expiry'); ?></strong><?php if($document->expiry_date): ?><span class="mt-1 block text-[10px] text-slate-400"><?php echo e($document->expiry_date->diffForHumans()); ?></span><?php endif; ?></td>
                            <td class="px-5 py-4"><span class="rounded-full px-2.5 py-1 text-[9px] font-bold uppercase <?php echo e($healthTone); ?>"><?php echo e($healthLabel); ?></span></td>
                            <td class="px-5 py-4 text-slate-500">v<?php echo e($document->version); ?></td>
                            <td class="px-5 py-4 text-right"><a href="<?php echo e(route('app.customers.documents.download', $document->id)); ?>" class="inline-flex items-center rounded-xl border border-violet-200 bg-violet-50 px-3 py-2 font-bold text-violet-700 hover:bg-violet-100">Download</a></td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr><td colspan="7" class="px-6 py-16 text-center"><strong class="block text-base text-slate-700">No documents found</strong><span class="mt-2 block text-sm text-slate-400">Adjust the filters or upload documents from a customer profile.</span><a href="<?php echo e(route('app.customers.index')); ?>" class="mt-4 inline-flex rounded-xl bg-violet-600 px-4 py-2 text-xs font-bold text-white">Find a customer</a></td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        <?php if($documents->hasPages()): ?><div class="border-t border-slate-100 px-5 py-4"><?php echo e($documents->links()); ?></div><?php endif; ?>
    </section>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\typingcenter\resources\views/tenant/customers/documents/index.blade.php ENDPATH**/ ?>