@extends('layouts.parent')
@section('title', 'Attendance')
@section('page_title', 'Child Attendance')

@section('content')
    <div class="card mb-3"><div class="card-body">
        <form method="GET" class="row g-2 align-items-end">
            <div class="col-md-5"><label class="form-label small">Child</label>
                <select name="student_id" class="form-select form-select-sm" onchange="this.form.submit()">
                    @foreach($children as $child)<option value="{{ $child->id }}" @selected($student && $student->id==$child->id)>{{ $child->name }}</option>@endforeach
                </select></div>
            <div class="col-md-4"><label class="form-label small">Month</label>
                <input type="month" name="month" value="{{ $month }}" class="form-control form-control-sm"></div>
            <div class="col-md-3"><button class="btn btn-sm btn-primary"><i class="bi bi-search me-1"></i>View</button></div>
        </form>
    </div></div>

    @if($student)
        <div class="row g-2 mb-3">
            @foreach(['present'=>'success','absent'=>'danger','leave'=>'info','late'=>'warning','half_day'=>'secondary'] as $st => $tone)
                <div class="col">
                    <div class="card text-center"><div class="card-body py-2">
                        <div class="h4 mb-0 text-{{ $tone }}">{{ $summary[$st] ?? 0 }}</div>
                        <div class="small text-muted text-capitalize">{{ str_replace('_',' ',$st) }}</div>
                    </div></div>
                </div>
            @endforeach
        </div>

        <div class="card"><div class="card-body">
            <table class="table table-sm table-hover align-middle">
                <thead><tr><th>Date</th><th>Day</th><th>Status</th><th>Remarks</th></tr></thead>
                <tbody>
                    @forelse($records as $r)
                        <tr>
                            <td>{{ $r->date->format('d M Y') }}</td>
                            <td class="small text-muted">{{ $r->date->format('l') }}</td>
                            <td><span class="badge bg-soft-{{ App\Models\StudentAttendance::statusColor($r->status) }} text-capitalize">{{ str_replace('_',' ',$r->status) }}</span></td>
                            <td class="small text-muted">{{ $r->remarks ?: '—' }}</td>
                        </tr>
                    @empty
                        <tr><td colspan="4" class="text-center text-muted py-4">No attendance recorded for this month.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div></div>
    @endif
@endsection
