@extends('layouts.app')
@section('title', 'Thực hiện điểm danh')
@section('content')
<div class="d-flex justify-content-between align-items-center mb-4">
<div><h3 class="fw-bold mb-1">Thực hiện điểm danh</h3><div class="text-muted">{{ $attendanceSession->title }} - {{ $attendanceSession->trainingClass->name ?? '' }}</div></div>
<a href="{{ route('attendance-sessions.index') }}" class="btn btn-outline-secondary"><i class="bi bi-arrow-left me-1"></i> Quay lại</a>
</div>
@if(session('success'))<div class="alert alert-success"><i class="bi bi-check-circle me-1"></i> {{ session('success') }}</div>@endif
<div class="card shadow-sm"><div class="card-body">
<form action="{{ route('attendance-sessions.save', $attendanceSession->id) }}" method="POST">@csrf
<table class="table table-hover align-middle">
<thead class="table-light"><tr><th>STT</th><th>Mã HV</th><th>Học viên</th><th>Trạng thái</th><th>Ghi chú</th></tr></thead>
<tbody>
@forelse($enrollments as $index => $enrollment)
@php $attendance = $attendances[$enrollment->id] ?? null; @endphp
<tr>
<td>{{ $index + 1 }}</td>
<td><strong>{{ $enrollment->student->code ?? '' }}</strong></td>
<td>{{ $enrollment->student->full_name ?? '' }}</td>
<td>
<select name="status[{{ $enrollment->id }}]" class="form-select">
@foreach(['Có mặt','Vắng có phép','Vắng không phép','Đi trễ'] as $status)
<option value="{{ $status }}" {{ ($attendance->status ?? 'Có mặt') == $status ? 'selected' : '' }}>{{ $status }}</option>
@endforeach
</select>
</td>
<td><input type="text" name="note[{{ $enrollment->id }}]" class="form-control" value="{{ $attendance->note ?? '' }}"></td>
</tr>
@empty
<tr><td colspan="5" class="text-center text-muted py-4">Lớp học này chưa có học viên đăng ký.</td></tr>
@endforelse
</tbody>
</table>
<div class="text-end"><button class="btn btn-primary"><i class="bi bi-save me-1"></i> Lưu điểm danh</button></div>
</form>
</div></div>
@endsection
