<?= $this->extend('layout/management_layout') ?>
<?= $this->section('content') ?>
<div class="container-fluid">
    <div class="wrapper">
        <div class="content"></div>
        <h1 class="text-center">Score Management</h1>
        <div class="d-flex justify-content-center">
            <div class="col-12 col-lg-10">
                <?= $this->include('partials/academic_filter') ?>
            </div>
        </div>
        <br>
<!-- Tabs navigation -->
<ul class="nav nav-tabs justify-content-center" id="gradingTabs" role="tablist">
    <?php foreach ($grades as $classId => $sections): ?>
        <li class="nav-item">
            <a class="nav-link <?= ($classId === 1) ? 'active' : '' ?>"
               id="grade<?= $classId ?>-tab"
               data-bs-toggle="tab"
               href="#grade<?= $classId ?>"
               role="tab"
               aria-controls="grade<?= $classId ?>"
               aria-selected="<?= ($classId === 1) ? 'true' : 'false' ?>">
                <?= $classId === 12 ? 'Youth' : "Grade $classId" ?>
            </a>
        </li>
    <?php endforeach; ?>
</ul>

<!-- Tabs content -->
<div class="tab-content mt-4">
    <?php foreach ($grades as $classId => $sections): ?>
        <div class="tab-pane fade <?= ($classId === 1) ? 'show active' : '' ?>" id="grade<?= $classId ?>" role="tabpanel">
            <?php foreach ($sections as $section): ?>
                <?php
                $sectionId = $section['class_section_id'];
                if (empty($studentsBySection[$sectionId])) continue;
                ?>
                <h4 class="text-center mt-4"><?= esc($section['class_section_name']) ?></h4>
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>Student Name</th>
                            <th>School ID</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($studentsBySection[$sectionId] as $student): ?>
                            <tr>
                                <td><?= esc($student['firstname'] . ' ' . $student['lastname']) ?></td>
                                <td><?= esc($student['school_id']) ?></td>
                                <td>
                                    <?php
                                        $types = ['homework', 'quiz', 'project', 'test', 'midterm', 'final', 'comments'];
                                        foreach ($types as $type):
                                    ?>
                                        <a href="<?= base_url("grading/$type/{$sectionId}/{$student['id']}") ?>" class="btn btn-sm btn-outline-primary m-1">
                                            <?= ucfirst($type) ?>
                                        </a>
                                    <?php endforeach; ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            <?php endforeach; ?>
        </div>
    <?php endforeach; ?>
</div>

<?= $this->endSection() ?>
