<?= $this->extend('layout/main_layout') ?>
<?= $this->section('content') ?>

<div class="container-xxl py-4">
  <div class="d-flex align-items-center justify-content-between flex-wrap gap-2 mb-3">
    <div>
      <h2 class="mb-0">Student Score Card</h2>
      <div class="text-muted small">Select a student to open their score card.</div>
    </div>
  </div>

  <?php if (empty($students)): ?>
    <div class="alert alert-warning">No students available for your account.</div>
  <?php else: ?>
    <div class="card shadow-sm">
      <div class="card-body table-responsive">
        <table class="table table-striped align-middle mb-0">
          <thead class="table-light">
            <tr>
              <th>School ID</th>
              <th>Student</th>
              <th class="text-end">Action</th>
            </tr>
          </thead>
          <tbody>
            <?php foreach ($students as $stu): ?>
              <?php
                $sid = (int)($stu['id'] ?? 0);
                $schoolId = trim((string)($stu['school_id'] ?? ''));
                $label = trim(($stu['firstname'] ?? '') . ' ' . ($stu['lastname'] ?? ''));
              ?>
              <tr>
                <td><?= esc($schoolId) ?></td>
                <td><?= esc($label) ?></td>
                <td class="text-end">
                  <form method="post" action="<?= site_url('student/score-card') ?>" class="d-inline">
                    <?= csrf_field() ?>
                    <input type="hidden" name="student_id" value="<?= $sid ?>">
                    <button type="submit" class="btn btn-sm btn-primary">Open</button>
                  </form>
                </td>
              </tr>
            <?php endforeach; ?>
          </tbody>
        </table>
      </div>
    </div>
  <?php endif; ?>
</div>

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