<?php $__env->startSection('title', 'Student Attendance'); ?>
<?php $__env->startSection('page_title', 'Student Attendance'); ?>
<?php $__env->startSection('breadcrumbs'); ?>
    <li class="breadcrumb-item"><a href="<?php echo e(route('dashboard')); ?>">Home</a></li>
    <li class="breadcrumb-item active">Student Attendance</li>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('page_actions'); ?>
    <a href="<?php echo e(route('attendance.students.report')); ?>" class="btn btn-outline-primary"><i class="bi bi-bar-chart me-1"></i>Monthly Report</a>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <div class="card mb-3"><div class="card-body">
        <form method="GET" class="row g-2 align-items-end">
            <div class="col-md-3"><label class="form-label small">Class</label>
                <select name="class_id" class="form-select form-select-sm" onchange="this.form.submit()">
                    <option value="">— Select class —</option>
                    <?php $__currentLoopData = $classes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($c->id); ?>" <?php if($classId==$c->id): echo 'selected'; endif; ?>><?php echo e($c->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select></div>
            <div class="col-md-3"><label class="form-label small">Section</label>
                <select name="section_id" class="form-select form-select-sm">
                    <option value="">All sections</option>
                    <?php $__currentLoopData = $sections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($s->id); ?>" <?php if($sectionId==$s->id): echo 'selected'; endif; ?>><?php echo e($s->name); ?></option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select></div>
            <div class="col-md-3"><label class="form-label small">Date</label>
                <input type="date" name="date" value="<?php echo e($date); ?>" 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>Load Roster</button></div>
        </form>
    </div></div>

    <?php if($classId && $students->isNotEmpty()): ?>
        <form method="POST" action="<?php echo e(route('attendance.students.store')); ?>">
            <?php echo csrf_field(); ?>
            <input type="hidden" name="class_id" value="<?php echo e($classId); ?>">
            <input type="hidden" name="section_id" value="<?php echo e($sectionId); ?>">
            <input type="hidden" name="date" value="<?php echo e($date); ?>">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <span><i class="bi bi-people me-1"></i><?php echo e($students->count()); ?> students &mdash; <?php echo e(\Illuminate\Support\Carbon::parse($date)->format('d M Y')); ?></span>
                    <button type="button" class="btn btn-sm btn-light border" id="markAllPresent"><i class="bi bi-check2-all me-1"></i>Mark all present</button>
                </div>
                <div class="card-body">
                    <table class="table table-hover align-middle">
                        <thead><tr><th>#</th><th>Student</th><th>Status</th><th>Remarks</th></tr></thead>
                        <tbody>
                            <?php $__currentLoopData = $students; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $student): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php $rec = $existing->get($student->id); $cur = $rec?->status ?? 'present'; ?>
                                <tr>
                                    <td><?php echo e($i + 1); ?></td>
                                    <td>
                                        <div class="d-flex align-items-center gap-2">
                                            <span class="sms-avatar sm"><?php echo e($student->initials); ?></span>
                                            <div><div class="fw-semibold"><?php echo e($student->name); ?></div><div class="small text-muted"><?php echo e($student->admission_number); ?></div></div>
                                        </div>
                                    </td>
                                    <td style="min-width:230px">
                                        <div class="btn-group btn-group-sm att-group" role="group">
                                            <?php $__currentLoopData = App\Models\StudentAttendance::STATUSES; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $st): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <input type="radio" class="btn-check" name="status[<?php echo e($student->id); ?>]" id="st<?php echo e($student->id); ?>_<?php echo e($st); ?>" value="<?php echo e($st); ?>" <?php if($cur===$st): echo 'checked'; endif; ?>>
                                                <label class="btn btn-outline-<?php echo e(App\Models\StudentAttendance::statusColor($st)); ?>" for="st<?php echo e($student->id); ?>_<?php echo e($st); ?>"><?php echo e(ucfirst(str_replace('_',' ',$st))); ?></label>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </div>
                                    </td>
                                    <td><input type="text" name="remarks[<?php echo e($student->id); ?>]" value="<?php echo e($rec?->remarks); ?>" class="form-control form-control-sm" placeholder="—"></td>
                                </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                </div>
                <div class="card-footer text-end">
                    <button class="btn btn-primary"><i class="bi bi-save me-1"></i>Save Attendance</button>
                </div>
            </div>
        </form>
        <?php $__env->startPush('scripts'); ?>
        <script>
            document.getElementById('markAllPresent').addEventListener('click', function(){
                document.querySelectorAll('input[id$="_present"]').forEach(r => r.checked = true);
            });
        </script>
        <?php $__env->stopPush(); ?>
    <?php elseif($classId): ?>
        <div class="card"><div class="card-body text-center text-muted py-4">No active students in this class/section.</div></div>
    <?php else: ?>
        <div class="card"><div class="card-body text-center text-muted py-4">Select a class and date to load the roster.</div></div>
    <?php endif; ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/u385418287/domains/itartificer.com/public_html/sms-erp/resources/views/attendance/students/index.blade.php ENDPATH**/ ?>