<?= $this->extend('layout/main_layout') ?>
<?= $this->section('content') ?>
<div class="container-xxl py-5">
    <div class="container">
        <div class="text-center mx-auto mb-5 wow fadeInUp" data-wow-delay="0.1s" style="max-width: 600px;">
            <br>
            <h1 class="mb3">Homework Scores</h1>
        </div>

        <?php if (session()->get('status')): ?>
            <div class="alert alert-success">
                <?= session()->get('status') ?>
            </div>
        <?php endif; ?>

        <form action="<?= route_to('updateHomeworkScores') ?>" method="post" onsubmit="return validateForm()">
            <input type="hidden" name="class_section_id" value="<?= $classSectionId ?>">

            <h2>Homework List for Class Section <?= $classSectionId; ?></h2>

            <h1>Homework List for Class Section ID: <?= esc($classSectionId) ?></h1>

            <?php if (!empty($students)): ?>
                <table class="table">
                    <thead>
                        <tr>
                            <th>Student Name</th>
                            <th>Homework</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($students as $student): ?>
                            <tr>
                                <td><?= esc($student['firstname']) . ' ' . esc($student['lastname']) ?></td>
                                <td>
                                    <?php if (isset($homeworkData[$student['id']])): ?>
                                        <?= esc($homeworkData[$student['id']]['score']) ?>
                                    <?php else: ?>
                                        No homework data available
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            <?php else: ?>
                <p>No students found for this class section.</p>
            <?php endif; ?>
    </div>
    <?= $this->endSection() ?>