@php use App\Services\BusyWindowService; use Carbon\Carbon; // Load all external busy windows with ±40 min buffer $busyWindows = BusyWindowService::getBusyRanges(); @endphp @include('partials.flash')

Calendar: {{ $start->toFormattedDateString() }} – {{ $end->toFormattedDateString() }}

Free Booked Closed (Admin) Busy (External) Closed (Past/≤ 2h)
@php $times = ['09:00:00','10:00:00','11:00:00','14:00:00','15:00:00','16:00:00']; @endphp @for ($i = 0; $i < 5; $i++) {{-- Mon–Fri --}} @endfor @foreach ($times as $time) @for ($weekday = 1; $weekday <= 5; $weekday++) {{-- 1=Mon . 5=Fri --}} @php $date = $start->copy()->addDays($weekday - 1)->toDateString(); // Find the recurring slot for this weekday+time $slot = $slots->first(function($s) use ($weekday, $time) { return (int)$s->weekday === $weekday && $s->time === $time; }); // Existing booking for that visible date? $booking = $slot ? $slot->bookings->firstWhere('date', $date) : null; // 2-hour rule $sessionStart = Carbon::createFromFormat('Y-m-d H:i:s', $date.' '.$time, $now->timezone); $minutesUntil = $now->diffInMinutes($sessionStart, false); $tooSoon = $minutesUntil <= 120; // External busy window check (±40 min buffer already applied) $isExternalBusy = BusyWindowService::isInBusyWindow($sessionStart, $busyWindows); // Assign background class $class = 'border p-2 text-center '; if ($booking?->status === 'booked') $class .= 'bg-red-200'; elseif ($booking?->status === 'blocked') $class .= 'bg-yellow-200'; elseif ($isExternalBusy) $class .= 'bg-amber-200'; elseif ($slot && !$booking && !$tooSoon) $class .= 'bg-green-100'; else $class .= 'bg-gray-100'; @endphp @endfor @endforeach
Time {{ $start->copy()->addDays($i)->format('D d M') }}
{{ substr($time, 0, 5) }} @if ($isExternalBusy) Busy (External) @elseif ($booking) {{ $booking->status === 'blocked' ? 'Closed' : 'Booked' }} @if ($booking->status === 'booked' && $booking->student_name)
{{ $booking->student_name }} @endif @elseif (!$slot) Not seeded @elseif ($tooSoon || $minutesUntil < 0) Closed @else @php $isStudent = isset($viewer) && $viewer === 'student'; @endphp @if ($slot) @if ($isStudent) @else @endif @else Free @endif @endif