<?php
require_once __DIR__ . '/_nav.php';
$pageTitle  = 'My Timetable';
$sidebarNav = teacherNav();
$u = function($p) { return \Core\View::url($p); };
?>
<div class="page-header"><div><h1>My Timetable</h1></div></div>
<div class="card">
  <div class="table-wrap">
    <table>
      <thead><tr><th>Day</th><th>Time</th><th>Subject</th><th>Stream</th><th>Room</th></tr></thead>
      <tbody>
        <?php foreach($days as $num => $name): ?>
        <?php if(!isset($grouped[$num])) continue; ?>
        <?php foreach($grouped[$num] as $i => $slot): ?>
        <tr>
          <?php if($i===0): ?><td rowspan="<?= count($grouped[$num]) ?>" style="font-weight:700;background:var(--primary-light);color:var(--primary)"><?= $name ?></td><?php endif; ?>
          <td><?= substr($slot['start_time'],0,5) ?> - <?= substr($slot['end_time'],0,5) ?></td>
          <td><strong><?= htmlspecialchars($slot['subject_name']) ?></strong></td>
          <td><?= htmlspecialchars($slot['stream_name']) ?></td>
          <td><?= htmlspecialchars($slot['room'] ?? '-') ?></td>
        </tr>
        <?php endforeach; ?>
        <?php endforeach; ?>
        <?php if(empty($grouped)): ?><tr><td colspan="5" style="text-align:center;padding:40px;color:var(--gray)">No timetable assigned yet</td></tr><?php endif; ?>
      </tbody>
    </table>
  </div>
</div>
