@foreach(['Mon','Tue','Wed','Thu','Fri','Sat','Sun'] as $day)
{{ $day }}
@endforeach
{{-- Calendar Grid --}}
@php
// Safely calculate correct calendar days and Monday-start padding using Carbon
$calMonth = \Carbon\Carbon::create($prevMonth->year, $prevMonth->month, 1)->addMonth();
$totalDays = $calMonth->daysInMonth;
// dayOfWeekIso is 1 for Mon, 7 for Sun. We subtract 1 to get 0-6 padding blocks.
$padDays = $calMonth->dayOfWeekIso - 1;
// Map records by day to ensure missing days don't collapse the calendar grid layout
$mappedRecords = [];
foreach($attendanceRecords as $rec) {
$mappedRecords[(int)$rec['day']] = $rec;
}
@endphp