<?php $__env->startSection('title', 'Front Desk Command Center'); ?>

<?php $__env->startSection('content'); ?>
<div class="space-y-5">
    <header class="flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
        <div>
            <p class="text-[10px] font-bold uppercase tracking-[.18em] text-orange-600">Reception & customer flow</p>
            <h1 class="mt-1 text-2xl font-bold text-[#0b1f38]">Front Desk Command Center</h1>
            <p class="mt-1 text-xs text-slate-500">Live check-ins, appointments, document readiness and pending collections.</p>
        </div>
        <div class="flex flex-wrap gap-2">
            <?php if(auth()->user()->hasPermission('queue.manage')): ?>
                <a href="<?php echo e(route('app.queue.index')); ?>" class="rounded-xl border border-slate-200 bg-white px-4 py-2.5 text-xs font-bold text-slate-700">Issue Queue Token</a>
            <?php endif; ?>
            <?php if(auth()->user()->hasPermission('applications.create')): ?>
                <a href="<?php echo e(route('app.applications.create')); ?>" class="rounded-xl bg-orange-600 px-4 py-2.5 text-xs font-bold text-white shadow-lg shadow-orange-200">+ New Application</a>
            <?php endif; ?>
        </div>
    </header>

    <section class="grid gap-3 sm:grid-cols-2 xl:grid-cols-5">
        <article class="erp-kpi-card"><div class="erp-kpi-icon bg-blue-50 text-blue-600">Q</div><div><p>Customers Waiting</p><strong><?php echo e(number_format($metrics['waiting'])); ?></strong><small><?php echo e($metrics['at_counter']); ?> currently at counter</small></div></article>
        <article class="erp-kpi-card"><div class="erp-kpi-icon bg-violet-50 text-violet-600">A</div><div><p>Today's Appointments</p><strong><?php echo e(number_format($metrics['appointments'])); ?></strong><small><?php echo e($metrics['appointments_completed']); ?> completed</small></div></article>
        <article class="erp-kpi-card"><div class="erp-kpi-icon bg-amber-50 text-amber-600">D</div><div><p>Document Exceptions</p><strong><?php echo e(number_format($metrics['documents_pending'])); ?></strong><small>Pending, missing or exception</small></div></article>
        <article class="erp-kpi-card"><div class="erp-kpi-icon bg-rose-50 text-rose-600">AED</div><div><p>Pending Collections</p><strong><?php echo e(number_format((float) $metrics['payments_pending'], 2)); ?></strong><small>Open invoice balance</small></div></article>
        <article class="erp-kpi-card"><div class="erp-kpi-icon bg-emerald-50 text-emerald-600">✓</div><div><p>Queue Progress</p><strong><?php echo e($metrics['waiting'] + $metrics['at_counter'] > 0 ? number_format(($metrics['at_counter'] / max(1, $metrics['waiting'] + $metrics['at_counter'])) * 100) : 100); ?>%</strong><small>Active flow at counters</small></div></article>
    </section>

    <div class="grid gap-5 xl:grid-cols-[1.45fr_.85fr]">
        <section class="erp-panel">
            <div class="erp-panel-heading"><div><h2>Live Waiting Queue</h2><p>Today’s active customer tokens in service priority order.</p></div><a href="<?php echo e(route('app.queue.index')); ?>">Open live board</a></div>
            <div class="mt-4 overflow-x-auto">
                <table class="erp-table">
                    <thead><tr><th>Token</th><th>Customer</th><th>Service</th><th>Check-in</th><th>Counter</th><th>Status</th></tr></thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $queueTokens; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $token): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td><strong class="text-orange-600"><?php echo e($token->token_number); ?></strong><small><?php echo e($token->service_date?->format('d M Y')); ?></small></td>
                                <td><strong><?php echo e($token->customer?->full_name_en ?? 'Walk-in customer'); ?></strong><small><?php echo e($token->customer?->primary_mobile ?? 'Customer not linked'); ?></small></td>
                                <td><strong><?php echo e($token->service_type); ?></strong><small><?php echo e($token->handler?->name ? 'Handled by '.$token->handler->name : 'Awaiting handler'); ?></small></td>
                                <td><strong><?php echo e($token->checked_in_at?->format('h:i A') ?? '—'); ?></strong><small><?php echo e($token->checked_in_at?->diffForHumans()); ?></small></td>
                                <td><strong><?php echo e($token->counter?->name ?? 'Not assigned'); ?></strong></td>
                                <td><span class="erp-status" data-status="<?php echo e($token->status); ?>"><?php echo e(str($token->status)->replace('_', ' ')->title()); ?></span></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr><td colspan="6"><div class="erp-empty"><span>Q</span><strong>No customers are waiting</strong><p>Issue a token when the next walk-in arrives.</p></div></td></tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </section>

        <section class="erp-panel">
            <div class="erp-panel-heading"><div><h2>Appointment Schedule</h2><p>Today’s booked and checked-in visitors.</p></div><a href="<?php echo e(route('app.queue.index')); ?>">Manage</a></div>
            <div class="mt-4 divide-y divide-slate-100">
                <?php $__empty_1 = true; $__currentLoopData = $appointments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $appointment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <article class="flex items-center gap-3 py-3 first:pt-0">
                        <div class="w-14 shrink-0 rounded-xl bg-slate-50 px-2 py-2 text-center text-[10px] font-bold text-slate-700"><?php echo e(\Carbon\Carbon::parse($appointment->appointment_time)->format('h:i')); ?><span class="block text-[8px] text-slate-400"><?php echo e(\Carbon\Carbon::parse($appointment->appointment_time)->format('A')); ?></span></div>
                        <div class="min-w-0 flex-1"><strong class="block truncate text-xs text-[#0b1f38]"><?php echo e($appointment->customer?->full_name_en ?? 'Unlinked customer'); ?></strong><small class="block truncate text-[10px] text-slate-500"><?php echo e($appointment->service?->name_en ?? 'General appointment'); ?></small></div>
                        <span class="erp-status" data-status="<?php echo e($appointment->status); ?>"><?php echo e(str($appointment->status)->replace('_', ' ')->title()); ?></span>
                    </article>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <div class="erp-empty"><span>A</span><strong>No appointments today</strong><p>New bookings will appear here immediately.</p></div>
                <?php endif; ?>
            </div>
        </section>
    </div>
</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/panels/front_desk.blade.php ENDPATH**/ ?>