@extends('student.layouts.app') @section('title', app()->getLocale() === 'ar' ? 'الحضور المجمع' : 'Attendance Overview') @section('content') @php use Illuminate\Support\Carbon; use Illuminate\Support\Str; $isAr = app()->getLocale() === 'ar'; $typeLabels = [ 'school' => $isAr ? 'حصة مدرسية' : 'School session', 'virtual' => $isAr ? 'حصة افتراضية' : 'Virtual session', 'excused' => $isAr ? 'غياب مبرر' : 'Excused', 'absence' => $isAr ? 'غياب' : 'Absence', 'late' => $isAr ? 'تأخر' : 'Late', ]; $typeColors = [ 'school' => 'bg-sky-100 text-sky-700 dark:bg-sky-500/20 dark:text-sky-400', 'virtual' => 'bg-violet-100 text-violet-700 dark:bg-violet-500/20 dark:text-violet-400', 'excused' => 'bg-amber-100 text-amber-700 dark:bg-amber-500/20 dark:text-amber-400', 'absence' => 'bg-red-100 text-red-700 dark:bg-red-500/20 dark:text-red-400', 'late' => 'bg-orange-100 text-orange-700 dark:bg-orange-500/20 dark:text-orange-400', ]; $flat = collect($attendances)->flatMap(fn($c) => collect($c)); $totalAbsences = $flat->count(); $summary = collect($courses)->map(function ($course) use ($attendances) { $records = collect($attendances[$course->id] ?? [])->sortByDesc(fn($a) => $a->date ?? $a->created_at)->values(); return ['course' => $course, 'records' => $records, 'by_type' => $records->groupBy('type')->map->count()]; })->filter(fn($s) => $s['records']->isNotEmpty()); @endphp
{{-- Header --}}

{{ $isAr ? 'سجل الغياب' : 'Absence Records' }}

{{ $isAr ? 'الحضور المجمع' : 'Attendance Overview' }}

{{ $isAr ? 'تفاصيل الغياب المسجّل لكل مادة.' : 'Recorded absences per course.' }}

{{ $isAr ? 'إجمالي الغياب' : 'Total' }}

{{ $totalAbsences }}

{{ $isAr ? 'سجل' : 'records' }}

{{ $isAr ? 'المواد' : 'Courses' }}

{{ $summary->count() }}

{{ $isAr ? 'بها غياب' : 'affected' }}

{{-- Empty --}} @if($summary->isEmpty())

{{ $isAr ? 'لا يوجد غياب مسجّل' : 'No absences recorded' }}

{{ $isAr ? 'لم يتم تسجيل أي غياب في أي مادة.' : 'No absences have been recorded in any course.' }}

@else
@foreach($summary as $s) @php $course = $s['course']; @endphp
{{-- Course Header --}}

{{ $course->subject?->name ?: $course->name }}

@if($course->teacher)

{{ $course->teacher->name }}

@endif
@foreach($s['by_type'] as $type => $count) {{ $typeLabels[$type] ?? Str::of($type)->replace('_',' ')->title() }} · {{ $count }} @endforeach {{ $isAr ? 'الإجمالي:' : 'Total:' }} {{ $s['records']->count() }}
{{-- Records --}}
@foreach($s['records'] as $rec) @php $date = Carbon::parse($rec->date ?? $rec->created_at); $color = $typeColors[$rec->type] ?? 'bg-zinc-100 text-zinc-600 dark:bg-zinc-800 dark:text-zinc-400'; @endphp

{{ $date->translatedFormat($isAr ? 'l، d MMM Y' : 'l, d MMM Y') }}

@if($rec->notes)

{{ $rec->notes }}

@endif
{{ $typeLabels[$rec->type] ?? $rec->type }}
@endforeach
@endforeach
@endif
@endsection