<?php
$pageTitle  = 'Assignments';
$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>';
$u = fn($p) => \Core\View::url($p);
?>
<div class="page-header"><div><h1>Assignments</h1></div></div>
<div class="card">
  <div class="table-wrap">
    <table>
      <thead><tr><th>Title</th><th>Subject</th><th>Teacher</th><th>Due Date</th><th>Marks</th><th>File</th></tr></thead>
      <tbody>
        <?php foreach($assignments['data'] as $a): ?>
        <tr>
          <td><div style="font-weight:500"><?= htmlspecialchars($a['title']) ?></div><?php if($a['description']): ?><div style="font-size:12px;color:var(--gray)"><?= htmlspecialchars(substr($a['description'],0,60)) ?></div><?php endif; ?></td>
          <td><?= htmlspecialchars($a['subject_name']) ?></td>
          <td><?= htmlspecialchars($a['teacher_name']) ?></td>
          <td><?= $a['due_date'] ?> <?= $a['due_date'] < date('Y-m-d') ? '<span class="badge badge-danger">Overdue</span>' : ($a['due_date']===date('Y-m-d')?'<span class="badge badge-warning">Today</span>':'') ?></td>
          <td><?= $a['total_marks'] ?></td>
          <td><?= $a['file_path'] ? '<a href="'.$u('storage/uploads/'.$a['file_path']).'" target="_blank" class="btn btn-sm btn-secondary"><i class="bi bi-download"></i></a>' : '-' ?></td>
        </tr>
        <?php endforeach; ?>
        <?php if(empty($assignments['data'])): ?><tr><td colspan="6" style="text-align:center;padding:40px;color:var(--gray)">No assignments yet</td></tr><?php endif; ?>
      </tbody>
    </table>
  </div>
  <div style="padding:14px"><?= \Core\View::paginate($assignments, $u('student/assignments')) ?></div>
</div>
