<?php $__env->startSection('title', 'Customer Service 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">Customer experience & case visibility</p><h1 class="mt-1 text-2xl font-bold text-[#0b1f38]">Customer Service Command Center</h1><p class="mt-1 text-xs text-slate-500">Answer inquiries using live application status and a complete communication trail.</p></div><div class="flex gap-2"><a href="<?php echo e(route('app.customers.index')); ?>" class="rounded-xl border border-slate-200 bg-white px-4 py-2.5 text-xs font-bold text-slate-700">Customer 360</a><?php if(auth()->user()->hasPermission('communications.view')): ?><a href="<?php echo e(route('app.communications.index')); ?>" class="rounded-xl bg-orange-600 px-4 py-2.5 text-xs font-bold text-white">Communication Center</a><?php endif; ?></div></header>

    <section class="grid gap-3 sm:grid-cols-2 xl:grid-cols-5">
        <?php $__currentLoopData = [
            ['Active Applications',$metrics['active_applications'],'text-blue-600'], ['Returned Cases',$metrics['returned_cases'],'text-amber-600'],
            ['Incoming (7 Days)',$metrics['incoming_messages'],'text-emerald-600'], ['Queued Updates',$metrics['queued_updates'],'text-violet-600'],
            ['Upcoming Visits',$metrics['appointments'],'text-orange-600']
        ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$label,$value,$color]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <article class="rounded-2xl border border-slate-200 bg-white p-4 shadow-sm"><p class="text-[9px] font-bold uppercase tracking-wider text-slate-400"><?php echo e($label); ?></p><strong class="mt-2 block text-2xl <?php echo e($color); ?>"><?php echo e(number_format($value)); ?></strong></article>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </section>

    <div class="grid gap-5 xl:grid-cols-2">
        <section class="erp-panel"><div class="erp-panel-heading"><div><h2>Cases Requiring Visibility</h2><p>Latest open customer applications and current workflow stages.</p></div><a href="<?php echo e(route('app.applications.index')); ?>">View directory</a></div><div class="mt-4 overflow-x-auto"><table class="erp-table"><thead><tr><th>Application</th><th>Customer</th><th>Service / Stage</th><th>Status</th></tr></thead><tbody>
            <?php $__empty_1 = true; $__currentLoopData = $recentApplications; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $application): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr><td><a href="<?php echo e(route('app.applications.show', $application->id)); ?>" class="font-bold text-orange-600"><?php echo e($application->application_number); ?></a><small><?php echo e($application->created_at->diffForHumans()); ?></small></td><td><strong><?php echo e($application->customer?->full_name_en ?? 'Customer unavailable'); ?></strong><small><?php echo e($application->customer?->primary_mobile); ?></small></td><td><strong><?php echo e($application->service?->name_en ?? 'Unassigned service'); ?></strong><small><?php echo e($application->currentStage?->stage_name_en ?? 'Start stage'); ?></small></td><td><span class="erp-status" data-status="<?php echo e($application->status); ?>"><?php echo e(str($application->status)->replace('_',' ')->title()); ?></span></td></tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="4"><div class="erp-empty"><span>C</span><strong>No active customer cases</strong><p>Open applications will appear here.</p></div></td></tr>
            <?php endif; ?>
        </tbody></table></div></section>

        <section class="erp-panel"><div class="erp-panel-heading"><div><h2>Recent Conversations</h2><p>Omnichannel messages with delivery status and record links.</p></div><?php if(auth()->user()->hasPermission('communications.view')): ?><a href="<?php echo e(route('app.communications.index')); ?>">Open center</a><?php endif; ?></div><div class="mt-4 divide-y divide-slate-100">
            <?php $__empty_1 = true; $__currentLoopData = $recentCommunications; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $message): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <article class="flex gap-3 py-3 first:pt-0"><div class="flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-orange-50 text-[10px] font-bold uppercase text-orange-600"><?php echo e(substr($message->channel,0,2)); ?></div><div class="min-w-0 flex-1"><div class="flex items-start justify-between gap-3"><strong class="truncate text-xs text-[#0b1f38]"><?php echo e($message->customer?->full_name_en ?? $message->recipient); ?></strong><span class="erp-status" data-status="<?php echo e($message->status); ?>"><?php echo e(ucfirst($message->status)); ?></span></div><p class="mt-1 truncate text-[10px] text-slate-500"><?php echo e($message->subject ?: str($message->message)->limit(90)); ?></p><small class="mt-1 block text-[9px] text-slate-400"><?php echo e(ucfirst($message->direction)); ?> · <?php echo e(ucfirst($message->channel)); ?> · <?php echo e($message->created_at->diffForHumans()); ?></small></div></article>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <div class="erp-empty"><span>M</span><strong>No communication history</strong><p>Messages sent through the communication center will be logged here.</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\customer_service.blade.php ENDPATH**/ ?>