<?php
$pageTitle  = 'My Results';
$sidebarNav = '<div class="nav-section">Student Portal</div>
<div class="nav-item"><a href="'.\Core\View::url('student/dashboard').'"><i class="bi bi-grid"></i> Dashboard</a></div>
<div class="nav-item"><a href="'.\Core\View::url('student/results').'"><i class="bi bi-bar-chart"></i> My Results</a></div>
<div class="nav-item"><a href="'.\Core\View::url('student/fees').'"><i class="bi bi-cash"></i> Fee Balance</a></div>
<div class="nav-item"><a href="'.\Core\View::url('student/attendance').'"><i class="bi bi-calendar-check"></i> Attendance</a></div>
<div class="nav-item"><a href="'.\Core\View::url('student/assignments').'"><i class="bi bi-file-earmark-text"></i> Assignments</a></div>';
?>
<div class="page-header"><div><h1>My Results</h1></div></div>
<?php foreach($grouped as $examName => $marks): ?>
<?php $pts = array_sum(array_column($marks,'points')); $cnt = count($marks); $mean = $cnt>0 ? \Models\Mark::pointsToGrade($pts/$cnt) : 'N/A'; ?>
<div class="card" style="margin-bottom:20px">
  <div class="card-header">
    <h5><?= htmlspecialchars($examName) ?></h5>
    <span class="badge badge-success">Mean: <?= $mean ?> (<?= $pts ?> pts)</span>
  </div>
  <div class="table-wrap">
    <table>
      <thead><tr><th>Subject</th><th>Score</th><th>Grade</th><th>Points</th><th>Remarks</th></tr></thead>
      <tbody>
        <?php foreach($marks as $m): ?>
        <tr>
          <td><?= htmlspecialchars($m['subject_name']) ?></td>
          <td><?= $m['score'] ?>/<?= $m['out_of'] ?></td>
          <td><span class="badge badge-info"><?= htmlspecialchars($m['grade']) ?></span></td>
          <td><?= $m['points'] ?></td>
          <td><?= htmlspecialchars($m['remarks'] ?? '') ?></td>
        </tr>
        <?php endforeach; ?>
      </tbody>
    </table>
  </div>
</div>
<?php endforeach; ?>
<?php if(empty($grouped)): ?><div class="card"><div class="card-body" style="text-align:center;padding:40px;color:var(--gray)">No published results yet</div></div><?php endif; ?>
