

<?php $__env->startSection('content'); ?>
<div class="container">
    <div class="card border-success shadow-sm">
        <div class="card-header bg-success text-white">
            <strong>Course Registration</strong>
        </div>
        <div class="card-body">
            <?php if(session('success')): ?>
                <div class="alert alert-success"><?php echo e(session('success')); ?></div>
            <?php endif; ?>

            <?php if($errors->any()): ?>
                <div class="alert alert-danger">
                    <strong>Validation Error:</strong> <?php echo e($errors->first()); ?>

                </div>
            <?php endif; ?>

            <form method="POST" action="<?php echo e(route('student.registration.store')); ?>">
                <?php echo csrf_field(); ?>

                <div class="form-group mb-3">
                    <label for="semester">Select Level & Semester</label>
                    <select name="semester" id="semester" class="form-select" required onchange="showCourses(this.value)">
                        <option value="">-- Choose Level & Semester --</option>
                        <?php $__currentLoopData = $courses->keys(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $group): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($group); ?>"><?php echo e($group); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div id="course-container" class="mt-3"></div>

                <button type="submit" class="btn btn-success mt-3">Submit Registration</button>
            </form>
        </div>
    </div>
</div>

<script>
    const allCourses = <?php echo json_encode($courses, 15, 512) ?>;

    function showCourses(selectedGroup) {
        const container = document.getElementById('course-container');
        container.innerHTML = '';

        if (!selectedGroup || !allCourses[selectedGroup]) {
            return;
        }

        const courses = allCourses[selectedGroup];

        let html = `
            <h5 class="text-primary mb-2">${selectedGroup}</h5>
            <div class="table-responsive">
                <table class="table table-striped table-bordered">
                    <thead class="table-secondary">
                        <tr>
                            <th>Course Code</th>
                            <th>Course Description</th>
                            <th>Credits</th>
                            <th>Select</th>
                        </tr>
                    </thead>
                    <tbody>
        `;

        courses.forEach(course => {
            html += `
                <tr>
                    <td>${course.course_code}</td>
                    <td>${course.course_description}</td>
                    <td>${course.credits}</td>
                    <td><input type="checkbox" name="courses[]" value="${course.course_code}"></td>
                </tr>
            `;
        });

        html += `
                    </tbody>
                </table>
            </div>
        `;

        container.innerHTML = html;
    }
</script>
<?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\studentportal\resources\views/student/registration.blade.php ENDPATH**/ ?>