<?php $__env->startSection('title', 'Renewal Documents'); ?>

<?php $__env->startSection('content'); ?>
<div class="mx-auto max-w-[1800px] 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="overflow-hidden rounded-[26px] border border-violet-100 bg-gradient-to-br from-white via-violet-50 to-orange-50 p-6 text-slate-950 shadow-sm">
        <div class="flex flex-col gap-5 lg:flex-row lg:items-center lg:justify-between">
            <div><p class="text-[10px] font-bold uppercase tracking-[.18em] text-violet-700">Document lifecycle control</p><h1 class="mt-2 text-2xl font-bold">Renewal Documents & Reminders</h1><p class="mt-2 max-w-2xl text-xs leading-5 text-slate-600">Track expiring passports, visas, Emirates IDs, permits and company documents. Update document status, assign owners and schedule customer reminders with a complete audit trail.</p></div>
            <div class="flex flex-wrap gap-2"><?php if(auth()->check() && auth()->user()->hasPermission('renewals.manage')): ?><form method="POST" action="<?php echo e(route('app.renewals.scan')); ?>"><?php echo csrf_field(); ?><button class="rounded-xl bg-orange-500 px-4 py-2.5 text-[10px] font-bold text-white shadow-lg">Run Expiry Scan & Reminders</button></form><?php endif; ?><a href="<?php echo e(route('app.work_queue')); ?>" class="rounded-xl border border-violet-200 bg-white px-4 py-2.5 text-[10px] font-bold text-violet-700 shadow-sm">Typist Command Center</a></div>
        </div>
    </section>

    <section class="grid grid-cols-2 gap-3 lg:grid-cols-3 xl:grid-cols-6">
        <?php $__currentLoopData = [
            ['Expired', $metrics['expired'], 'text-rose-600', ['window' => 'expired']],
            ['Expiring today', $metrics['today'], 'text-orange-600', []],
            ['Next 7 days', $metrics['seven_days'], 'text-amber-600', ['window' => 7]],
            ['Next 30 days', $metrics['thirty_days'], 'text-sky-600', ['window' => 30]],
            ['In progress', $metrics['in_progress'], 'text-emerald-600', ['status' => 'contacted']],
            ['Scheduled reminders', $metrics['scheduled_reminders'], 'text-violet-600', ['reminder_due' => 1]],
        ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$label, $count, $color, $query]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <a href="<?php echo e(route('app.renewals.index', $query)); ?>" class="rounded-2xl border border-slate-200 bg-white p-4 shadow-sm transition hover:-translate-y-0.5 hover:border-violet-300 hover:shadow-lg"><p class="text-[9px] font-bold uppercase tracking-wider text-slate-400"><?php echo e($label); ?></p><p class="mt-2 text-3xl font-black <?php echo e($color); ?>"><?php echo e(number_format($count)); ?></p></a>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </section>

    <section class="overflow-hidden rounded-[24px] border border-slate-200 bg-white shadow-sm">
        <div class="border-b border-slate-100 p-4">
            <div class="flex flex-col gap-3 xl:flex-row xl:items-center xl:justify-between"><div><h2 class="text-sm font-bold text-[#0b1f38]">Renewal Control Queue</h2><p class="mt-1 text-[10px] text-slate-400">Open a record to edit its document status, pipeline stage and reminder schedule.</p></div><span class="rounded-xl bg-violet-50 px-3 py-2 text-[9px] font-bold text-violet-700"><?php echo e(number_format($opportunities->total())); ?> records</span></div>
            <form class="mt-4 grid grid-cols-1 gap-2 md:grid-cols-2 xl:grid-cols-[minmax(240px,1fr)_repeat(3,180px)_auto]">
                <input name="q" value="<?php echo e(request('q')); ?>" placeholder="Renewal, customer, company or document..." class="erp-input h-10 bg-slate-50 text-[10px]">
                <select name="status" class="erp-input h-10 bg-slate-50 text-[10px]"><option value="">All pipeline stages</option><?php $__currentLoopData = ['upcoming','reminder_scheduled','reminder_sent','contacted','interested','application_created','completed','lost']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($status); ?>" <?php if(request('status')===$status): echo 'selected'; endif; ?>><?php echo e(str($status)->replace('_',' ')->title()); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
                <select name="entity_type" class="erp-input h-10 bg-slate-50 text-[10px]"><option value="">All entity types</option><?php $__currentLoopData = ['customer','corporate_employee','company','tenant_employee','company_compliance']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($type); ?>" <?php if(request('entity_type')===$type): echo 'selected'; endif; ?>><?php echo e(str($type)->replace('_',' ')->title()); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
                <select name="document_status" class="erp-input h-10 bg-slate-50 text-[10px]"><option value="">All document statuses</option><?php $__currentLoopData = ['active','expiring','expired','renewal_in_progress','renewed','on_hold','cancelled']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($status); ?>" <?php if(request('document_status')===$status): echo 'selected'; endif; ?>><?php echo e(str($status)->replace('_',' ')->title()); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
                <?php if(request('reminder_due')): ?><input type="hidden" name="reminder_due" value="1"><?php endif; ?>
                <div class="flex gap-2"><button class="h-10 rounded-xl bg-[#0b1f38] px-4 text-[10px] font-bold text-white">Filter</button><a href="<?php echo e(route('app.renewals.index')); ?>" class="grid h-10 place-items-center rounded-xl border border-slate-200 px-3 text-[10px] font-bold text-slate-500">Reset</a></div>
            </form>
        </div>

        <div class="overflow-x-auto">
            <table class="erp-table">
                <thead><tr><th>Renewal / Entity</th><th>Document</th><th>Expiry</th><th>Document Status</th><th>Next Reminder</th><th>Pipeline</th><th>Owner</th><th>Action</th></tr></thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $opportunities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $opportunity): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php ($days = (int) now()->startOfDay()->diffInDays($opportunity->expiry_date->copy()->startOfDay(), false)); ?>
                        <tr>
                            <td><strong class="text-violet-700"><?php echo e($opportunity->renewal_number); ?></strong><small><?php echo e($opportunity->customer?->full_name_en ?? $opportunity->corporateEmployee?->full_name ?? $opportunity->company?->name_en ?? $opportunity->employee?->full_name ?? auth()->user()->tenant->company_name); ?></small></td>
                            <td><strong><?php echo e(str($opportunity->document_type)->replace('_',' ')->title()); ?></strong><small><?php echo e($opportunity->document_number ?: 'No document number'); ?></small></td>
                            <td><strong class="<?php echo e($days < 0 ? 'text-rose-600' : ($days <= 7 ? 'text-amber-600' : '')); ?>"><?php echo e($opportunity->expiry_date->format('d M Y')); ?></strong><small><?php echo e($days < 0 ? abs($days).' days overdue' : $days.' days remaining'); ?></small></td>
                            <td><span class="erp-status" data-status="<?php echo e($opportunity->document_status); ?>"><?php echo e(str($opportunity->document_status)->replace('_',' ')->title()); ?></span><small><?php echo e($opportunity->reminder_enabled ? 'Reminder enabled' : 'Reminder disabled'); ?></small></td>
                            <td><strong class="<?php echo e($opportunity->next_reminder_at ? 'text-violet-700' : 'text-slate-400'); ?>"><?php echo e($opportunity->next_reminder_at?->format('d M, h:i A') ?? 'Not scheduled'); ?></strong><small><?php echo e($opportunity->reminder_channel ? str($opportunity->reminder_channel)->replace('_',' ')->title() : 'Automatic rules active'); ?></small></td>
                            <td><span class="erp-status" data-status="<?php echo e($opportunity->status); ?>"><?php echo e(str($opportunity->status)->replace('_',' ')->title()); ?></span></td>
                            <td><strong><?php echo e($opportunity->assignedUser?->name ?? 'Unassigned'); ?></strong><small><?php echo e(str($opportunity->entity_type)->replace('_',' ')->title()); ?></small></td>
                            <td><a href="<?php echo e(route('app.renewals.show', $opportunity->id)); ?>" class="rounded-lg bg-[#0b1f38] px-3 py-2 text-[9px] font-bold text-white">Manage Renewal</a></td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr><td colspan="8"><div class="erp-empty"><span>RN</span><strong>No renewal opportunities yet</strong><p>Run the expiry scan after adding documents with expiry dates.</p></div></td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        <div class="flex flex-col gap-3 border-t border-slate-100 p-4 sm:flex-row sm:items-center sm:justify-between"><p class="text-[9px] text-slate-400"><?php echo e(number_format($reminderCount)); ?> total reminder log entries</p><?php echo e($opportunities->links()); ?></div>
    </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\renewals\dashboard.blade.php ENDPATH**/ ?>