<?php $__env->startSection('title', 'Application Directory'); ?>

<?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-sky-100 bg-gradient-to-br from-white via-sky-50 to-orange-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-sky-700">Live service register</span>
                <h1 class="mt-2 text-2xl font-bold tracking-tight text-slate-950 sm:text-3xl">Application directory</h1>
                <p class="mt-2 max-w-2xl text-sm text-slate-600">Track ownership, processing stage, fees and customer service accountability from one desk.</p>
            </div>
            <div class="flex flex-wrap gap-2">
                <a href="<?php echo e(route('app.work_queue')); ?>" class="rounded-xl border border-slate-200 bg-white px-4 py-2.5 text-xs font-bold text-slate-700 shadow-sm hover:border-sky-300">Open work queue</a>
                <a href="<?php echo e(route('app.applications.kanban')); ?>" class="rounded-xl border border-slate-200 bg-white px-4 py-2.5 text-xs font-bold text-slate-700 shadow-sm hover:border-sky-300">Kanban</a>
                <a href="<?php echo e(route('app.applications.create')); ?>" class="rounded-xl bg-orange-500 px-4 py-2.5 text-xs font-bold text-white shadow-sm hover:bg-orange-600">+ New application</a>
            </div>
        </div>
    </section>

    <section class="grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
        <?php $__currentLoopData = [
            ['Active applications', $metrics['active'], 'bg-sky-100 text-sky-700'],
            ['Completed today', $metrics['completed_today'], 'bg-emerald-100 text-emerald-700'],
            ['Returned for correction', $metrics['returned'], 'bg-orange-100 text-orange-700'],
            ['SLA attention', $metrics['sla_risk'], '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="rounded-3xl border border-slate-200 bg-white p-4 shadow-sm">
        <div class="grid gap-3 md:grid-cols-2 xl:grid-cols-6">
            <label class="xl:col-span-2"><span class="sr-only">Search</span><input name="q" value="<?php echo e(request('q')); ?>" class="w-full rounded-xl border-slate-200 bg-slate-50 px-4 py-2.5 text-xs focus:border-sky-400 focus:ring-sky-200" placeholder="Search reference, customer or service"></label>
            <select name="status" class="rounded-xl border-slate-200 bg-slate-50 px-3 py-2.5 text-xs"><option value="">All statuses</option><?php $__currentLoopData = ['draft','submitted','in_progress','pending','returned','completed','delivered','rejected','cancelled']; $__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="priority" class="rounded-xl border-slate-200 bg-slate-50 px-3 py-2.5 text-xs"><option value="">All priorities</option><?php $__currentLoopData = ['normal','high','urgent','vip']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $priority): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($priority); ?>" <?php if(request('priority') === $priority): echo 'selected'; endif; ?>><?php echo e(ucfirst($priority)); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
            <select name="stage_id" class="rounded-xl border-slate-200 bg-slate-50 px-3 py-2.5 text-xs"><option value="">All stages</option><?php $__currentLoopData = $stages; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stage): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($stage->id); ?>" <?php if((string) request('stage_id') === (string) $stage->id): echo 'selected'; endif; ?>><?php echo e($stage->stage_name_en); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
            <div class="flex gap-2"><button class="flex-1 rounded-xl bg-slate-900 px-4 py-2.5 text-xs font-bold text-white">Filter</button><a href="<?php echo e(route('app.applications.index')); ?>" class="rounded-xl border border-slate-200 px-3 py-2.5 text-xs font-bold text-slate-500">Reset</a></div>
        </div>
        <details class="mt-3 border-t border-slate-100 pt-3" <?php if(request('attended_by') || request('typed_by')): ?> open <?php endif; ?>>
            <summary class="cursor-pointer text-xs font-bold text-sky-700">Service accountability filters</summary>
            <div class="mt-3 grid gap-3 md:grid-cols-2">
                <select name="attended_by" class="rounded-xl border-slate-200 bg-slate-50 px-3 py-2.5 text-xs"><option value="">Any customer attendant</option><?php $__currentLoopData = $teamMembers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $member): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($member->id); ?>" <?php if((string) request('attended_by') === (string) $member->id): echo 'selected'; endif; ?>><?php echo e($member->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
                <select name="typed_by" class="rounded-xl border-slate-200 bg-slate-50 px-3 py-2.5 text-xs"><option value="">Any typist</option><?php $__currentLoopData = $teamMembers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $member): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($member->id); ?>" <?php if((string) request('typed_by') === (string) $member->id): echo 'selected'; endif; ?>><?php echo e($member->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></select>
            </div>
        </details>
    </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-[1100px] 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">Reference</th><th class="px-5 py-4">Customer & service</th><th class="px-5 py-4">Customer attended by</th><th class="px-5 py-4">Typist / owner</th><th class="px-5 py-4">Stage</th><th class="px-5 py-4">Status</th><th class="px-5 py-4">Fee</th><th class="px-5 py-4 text-right">Action</th></tr></thead>
                <tbody class="divide-y divide-slate-100">
                    <?php $__empty_1 = true; $__currentLoopData = $applications; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $application): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            $priorityTone = in_array($application->priority, ['urgent','vip']) ? 'bg-orange-100 text-orange-700' : ($application->priority === 'high' ? 'bg-amber-100 text-amber-700' : 'bg-slate-100 text-slate-600');
                            $statusTone = in_array($application->status, ['completed','delivered']) ? 'bg-emerald-100 text-emerald-700' : ($application->status === 'returned' ? 'bg-red-100 text-red-700' : 'bg-sky-100 text-sky-700');
                        ?>
                        <tr class="transition hover:bg-sky-50/40">
                            <td class="px-5 py-4"><a href="<?php echo e(route('app.applications.show', $application->id)); ?>" class="font-bold text-sky-700 hover:text-orange-600"><?php echo e($application->application_number); ?></a><span class="mt-1 block w-fit rounded-full px-2 py-0.5 text-[9px] font-bold uppercase <?php echo e($priorityTone); ?>"><?php echo e($application->priority); ?></span></td>
                            <td class="px-5 py-4"><strong class="block text-slate-900"><?php echo e($application->customer?->full_name_en ?? 'Customer unavailable'); ?></strong><span class="mt-1 block text-slate-500"><?php echo e($application->service?->name_en ?? 'Service unavailable'); ?></span></td>
                            <td class="px-5 py-4"><strong class="block text-slate-800"><?php echo e($application->attendedBy?->name ?? 'Not recorded'); ?></strong><span class="mt-1 block text-[10px] text-slate-400">Front desk service</span></td>
                            <td class="px-5 py-4"><strong class="block text-slate-800"><?php echo e($application->typedByUser?->name ?? $application->assignedUser?->name ?? 'Unassigned'); ?></strong><span class="mt-1 block text-[10px] text-slate-400"><?php echo e($application->typing_started_at ? 'Started '.$application->typing_started_at->diffForHumans() : 'Not started'); ?></span></td>
                            <td class="px-5 py-4 text-slate-600"><?php echo e($application->currentStage?->stage_name_en ?? 'Intake'); ?></td>
                            <td class="px-5 py-4"><span class="rounded-full px-2.5 py-1 text-[9px] font-bold uppercase <?php echo e($statusTone); ?>"><?php echo e(str($application->status)->replace('_',' ')); ?></span></td>
                            <td class="px-5 py-4 font-bold text-slate-900">AED <?php echo e(number_format($application->total_price ?? 0, 2)); ?></td>
                            <td class="px-5 py-4 text-right"><a href="<?php echo e(route('app.applications.show', $application->id)); ?>" class="inline-flex rounded-xl border border-slate-200 bg-white px-3 py-2 font-bold text-slate-700 hover:border-orange-300 hover:text-orange-600">Open 360°</a></td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr><td colspan="8" class="px-6 py-16 text-center"><strong class="block text-base text-slate-700">No applications match this view</strong><span class="mt-2 block text-sm text-slate-400">Clear the filters or start a new customer application.</span><a href="<?php echo e(route('app.applications.create')); ?>" class="mt-4 inline-flex rounded-xl bg-orange-500 px-4 py-2 text-xs font-bold text-white">Create application</a></td></tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
        <?php if($applications->hasPages()): ?><div class="border-t border-slate-100 px-5 py-4"><?php echo e($applications->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\applications\index.blade.php ENDPATH**/ ?>