@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() }}
@foreach ($times as $time)
Time
@for ($i = 0; $i < 5; $i++) {{-- Mon–Fri --}}
{{ $start->copy()->addDays($i)->format('D d M') }}
@endfor
@endforeach
{{ substr($time, 0, 5) }}
@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
@if ($isExternalBusy)
Busy (External)
@elseif ($booking)
{{ $booking->status === 'blocked' ? 'Closed' : 'Booked' }}
@if ($booking->status === 'booked' && $booking->student_name)
@endfor
{{ $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