<?php $__env->startSection('title', 'Enter Marks'); ?>
<?php $__env->startSection('page-title', 'Enter Marks'); ?>
<?php $__env->startSection('sidebar-nav'); ?>
<div class="nav-item"><a href="<?php echo e(route('teacher.dashboard')); ?>"><i class="bi bi-grid"></i> Dashboard</a></div>
<div class="nav-item"><a href="<?php echo e(route('teacher.marks')); ?>"><i class="bi bi-pencil-square"></i> Enter Marks</a></div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="page-header"><div><h1>Enter Marks</h1></div></div>

<div class="card" style="margin-bottom:20px;">
    <div class="card-body">
        <form method="GET" style="display:flex;gap:12px;flex-wrap:wrap;align-items:flex-end;">
            <div class="form-group" style="margin:0;flex:1;min-width:160px;">
                <label>Exam</label>
                <select name="exam_id">
                    <option value="">Select Exam</option>
                    <?php $__currentLoopData = $exams; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $exam): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($exam->id); ?>" <?php echo e(request('exam_id') == $exam->id ? 'selected' : ''); ?>><?php echo e($exam->name); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="form-group" style="margin:0;flex:1;min-width:160px;">
                <label>Stream</label>
                <select name="stream_id">
                    <option value="">Select Stream</option>
                    <?php $__currentLoopData = $streams; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($s->stream_id); ?>" <?php echo e(request('stream_id') == $s->stream_id ? 'selected' : ''); ?>>
                            <?php echo e($s->stream->schoolClass->name); ?> <?php echo e($s->stream->name); ?>

                        </option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="form-group" style="margin:0;flex:1;min-width:160px;">
                <label>Subject</label>
                <select name="subject_id">
                    <option value="">Select Subject</option>
                    <?php $__currentLoopData = $streams; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($s->subject_id); ?>" <?php echo e(request('subject_id') == $s->subject_id ? 'selected' : ''); ?>>
                            <?php echo e($s->subject->name); ?>

                        </option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <button type="submit" class="btn btn-primary">Load Students</button>
        </form>
    </div>
</div>

<?php if($students->count()): ?>
<div class="card">
    <div class="card-header">
        <h5><?php echo e($selectedExam->name); ?> &mdash; <?php echo e($selectedStream->schoolClass->name); ?> <?php echo e($selectedStream->name); ?> &mdash; <?php echo e($selectedSubject->name); ?></h5>
    </div>
    <div class="card-body" style="padding:0;">
        <form method="POST" action="<?php echo e(route('teacher.marks.save')); ?>">
            <?php echo csrf_field(); ?>
            <input type="hidden" name="exam_id" value="<?php echo e($selectedExam->id); ?>">
            <input type="hidden" name="stream_id" value="<?php echo e($selectedStream->id); ?>">
            <input type="hidden" name="subject_id" value="<?php echo e($selectedSubject->id); ?>">
            <div class="table-wrap">
                <table>
                    <thead><tr><th>#</th><th>Student</th><th>Score (/100)</th><th>Grade</th></tr></thead>
                    <tbody>
                        <?php $__currentLoopData = $students; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $student): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php $mark = $student->marks->first(); ?>
                        <tr>
                            <td><?php echo e($i + 1); ?></td>
                            <td>
                                <div style="font-weight:500;"><?php echo e($student->user->name); ?></div>
                                <div style="font-size:12px;color:var(--gray);"><?php echo e($student->admission_no); ?></div>
                            </td>
                            <td>
                                <input type="number" name="marks[<?php echo e($student->id); ?>]" value="<?php echo e($mark?->score); ?>"
                                    min="0" max="100" step="0.5" style="width:90px;" class="mark-input" data-row="<?php echo e($i); ?>">
                            </td>
                            <td><span class="badge badge-info" id="grade-<?php echo e($i); ?>"><?php echo e($mark?->grade ?? '-'); ?></span></td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
            <div style="padding:16px;border-top:1px solid var(--border);">
                <button type="submit" class="btn btn-primary"><i class="bi bi-save"></i> Save Marks</button>
            </div>
        </form>
    </div>
</div>
<?php endif; ?>

<?php $__env->startPush('scripts'); ?>
<script>
const grades = [[80,'A'],[75,'A-'],[70,'B+'],[65,'B'],[60,'B-'],[55,'C+'],[50,'C'],[45,'C-'],[40,'D+'],[35,'D'],[30,'D-'],[0,'E']];
function getGrade(s) { for (const [m,g] of grades) if (s >= m) return g; return 'E'; }
document.querySelectorAll('.mark-input').forEach(input => {
    input.addEventListener('input', function() {
        const g = this.value !== '' ? getGrade(parseFloat(this.value)) : '-';
        document.getElementById('grade-' + this.dataset.row).textContent = g;
    });
});
</script>
<?php $__env->stopPush(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\cbe\resources\views\teacher\marks-entry.blade.php ENDPATH**/ ?>