<?php $__env->startSection('title', 'Room inspections'); ?>

<?php $__env->startSection('content'); ?>
<div x-data="{ create: false }">
    <div class="mb-5 flex flex-wrap items-center justify-between gap-3">
        <div>
            <h1 class="text-xl font-extrabold text-slate-900 lg:text-2xl">Room inspections</h1>
            <p class="text-sm text-slate-500">Walk each room, tick every amenity, auto-raise fixes.</p>
        </div>
        <div class="flex gap-2">
            <a href="<?php echo e(route('epelcon.inspections.amenities')); ?>"
               class="rounded-xl bg-white px-4 py-2.5 text-sm font-bold text-slate-700 shadow-sm ring-1 ring-slate-200 hover:bg-slate-50">
                Amenity list
            </a>
            <button @click="create = true"
                    class="rounded-xl bg-indigo-600 px-4 py-2.5 text-sm font-bold text-white shadow-lg shadow-indigo-600/25 hover:bg-indigo-700">
                + Start inspection
            </button>
        </div>
    </div>

    <div class="mb-5 grid grid-cols-2 gap-3 sm:grid-cols-4">
        <div class="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200">
            <p class="text-xs font-bold uppercase text-slate-400">In progress</p>
            <p class="mt-1 text-2xl font-extrabold text-sky-600"><?php echo e($counts['in_progress']); ?></p>
        </div>
        <div class="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200">
            <p class="text-xs font-bold uppercase text-slate-400">Completed today</p>
            <p class="mt-1 text-2xl font-extrabold text-emerald-600"><?php echo e($counts['completed_today']); ?></p>
        </div>
        <div class="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200">
            <p class="text-xs font-bold uppercase text-slate-400">Avg issues / inspection</p>
            <p class="mt-1 text-2xl font-extrabold text-amber-600"><?php echo e($counts['avg_issues']); ?></p>
        </div>
        <div class="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200">
            <p class="text-xs font-bold uppercase text-slate-400">Rooms un-inspected (7d)</p>
            <p class="mt-1 text-2xl font-extrabold text-rose-600"><?php echo e($counts['rooms_without']); ?></p>
        </div>
    </div>

    <form method="GET" class="mb-4 flex flex-wrap gap-2">
        <select name="room" onchange="this.form.submit()"
                class="rounded-xl border-slate-200 text-sm">
            <option value="">All rooms</option>
            <?php $__currentLoopData = $rooms; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $room): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <option value="<?php echo e($room->id); ?>" <?php if(request('room') == $room->id): echo 'selected'; endif; ?>>Room <?php echo e($room->number); ?></option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </select>
        <div class="no-scrollbar flex gap-2 overflow-x-auto">
            <?php $__currentLoopData = ['' => 'All', 'in_progress' => 'In progress', 'completed' => 'Completed']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <a href="<?php echo e(route('epelcon.inspections.index', array_filter(['status' => $value, 'room' => request('room')]))); ?>"
                   class="shrink-0 rounded-full px-4 py-2 text-xs font-bold <?php echo e(request('status', '') === $value ? 'bg-slate-900 text-white' : 'bg-white text-slate-600 ring-1 ring-slate-200'); ?>">
                    <?php echo e($label); ?>

                </a>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
    </form>

    <div class="space-y-3">
        <?php $__empty_1 = true; $__currentLoopData = $inspections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $inspection): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <?php
                $stat = [
                    'in_progress' => 'bg-sky-100 text-sky-700',
                    'completed' => 'bg-emerald-100 text-emerald-700',
                ][$inspection->overall_status] ?? 'bg-slate-100 text-slate-600';
            ?>
            <a href="<?php echo e(route('epelcon.inspections.show', $inspection)); ?>"
               class="block rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200 hover:ring-indigo-300">
                <div class="flex flex-wrap items-center gap-3">
                    <div class="flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-indigo-50 font-bold text-indigo-700">
                        <?php echo e($inspection->room->number ?? '—'); ?>

                    </div>
                    <div class="min-w-0 flex-1">
                        <p class="font-bold text-slate-900">
                            Room <?php echo e($inspection->room->number ?? '—'); ?>

                            <?php if($inspection->issues_found > 0): ?>
                                <span class="ml-1 rounded-full bg-rose-100 px-2 py-0.5 text-[10px] font-bold uppercase text-rose-700">
                                    <?php echo e($inspection->issues_found); ?> issue<?php echo e($inspection->issues_found === 1 ? '' : 's'); ?>

                                </span>
                            <?php endif; ?>
                        </p>
                        <p class="text-xs text-slate-500">
                            <?php echo e($inspection->inspector->name ?? 'Unassigned'); ?>

                            · <?php echo e($inspection->inspected_at?->format('D j M, H:i') ?? '—'); ?>

                        </p>
                    </div>
                    <span class="rounded-full px-2.5 py-1 text-[10px] font-bold uppercase <?php echo e($stat); ?>">
                        <?php echo e(str_replace('_', ' ', $inspection->overall_status)); ?>

                    </span>
                </div>
            </a>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <div class="rounded-2xl bg-white p-10 text-center text-slate-400 shadow-sm ring-1 ring-slate-200">
                No inspections yet. Start one to build the room's checklist.
            </div>
        <?php endif; ?>
    </div>

    <div class="mt-5"><?php echo e($inspections->links()); ?></div>

    
    <div x-cloak x-show="create" class="fixed inset-0 z-50 flex items-end justify-center sm:items-center">
        <div class="absolute inset-0 bg-slate-900/50 backdrop-blur-sm" @click="create = false"></div>
        <div x-show="create" x-transition
             class="relative w-full max-w-md rounded-t-3xl bg-white p-6 shadow-2xl sm:rounded-3xl">
            <h2 class="mb-4 text-lg font-extrabold">Start a room inspection</h2>
            <form method="POST" action="<?php echo e(route('epelcon.inspections.start')); ?>" class="space-y-4"><?php echo csrf_field(); ?>
                <label class="block">
                    <span class="mb-1 block text-xs font-bold uppercase text-slate-500">Room</span>
                    <select name="room_id" required class="w-full rounded-xl border-slate-200 text-sm">
                        <?php $__currentLoopData = $rooms; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $room): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($room->id); ?>">
                                Room <?php echo e($room->number); ?> (<?php echo e(str_replace('_', ' ', $room->housekeeping_status)); ?>)
                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </label>
                <p class="rounded-xl bg-slate-50 p-3 text-xs text-slate-600">
                    A checklist will be built from every active amenity in the master list.
                    Manage that list from
                    <a href="<?php echo e(route('epelcon.inspections.amenities')); ?>" class="font-bold text-indigo-600">Amenity list</a>.
                </p>
                <div class="flex justify-end gap-2">
                    <button type="button" @click="create = false" class="rounded-xl px-4 py-2.5 text-sm font-bold text-slate-500">Cancel</button>
                    <button class="rounded-xl bg-indigo-600 px-5 py-2.5 text-sm font-bold text-white">Start inspection</button>
                </div>
            </form>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.epelcon', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\wamp64\www\hms\resources\views/epelcon/inspections/index.blade.php ENDPATH**/ ?>