<?php include_once __DIR__ . '/../layouts/head.php'; ?>
<div class="container py-4" style="max-width: 900px;">
  <div class="shadow-sm bg-white rounded overflow-hidden border p-4">
    <h4 class="mb-4 fw-bold">Detail Nilai Mahasiswa</h4>

    <table class="table table-sm">
      <tr>
        <th style="width: 200px;">NIM</th>
        <td><?= htmlspecialchars($nim) ?></td>
      </tr>
      <tr>
        <th>Kode Mata Kuliah</th>
        <td><?= htmlspecialchars($kode_mk) ?></td>
      </tr>
      <tr>
        <th>Semester</th>
        <td><?= htmlspecialchars($smt) ?></td>
      </tr>
    </table>

    <p class="mt-4"><strong>Bobot Penilaian:</strong></p>
    <ul>
      <li>Presensi: 20%</li>
      <li>Tugas: 20%</li>
      <li>UTS: 30%</li>
      <li>UAS: 30%</li>
    </ul>

    <table class="table table-bordered mt-3">
      <thead class="table-light">
        <tr>
          <th>Komponen</th>
          <th>Nilai Asli</th>
          <th>Nilai Setelah %</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Presensi</td>
          <td><?= $nilai_presensi !== null ? $nilai_presensi : '-' ?></td>
          <td><?= $nilai_presensi !== null ? round($nilai_presensi * 0.2, 2) : '-' ?></td>
        </tr>
        <tr>
          <td>Tugas</td>
          <td><?= $nilai_tugas !== null ? $nilai_tugas : '-' ?></td>
          <td><?= $nilai_tugas !== null ? round($nilai_tugas * 0.2, 2) : '-' ?></td>
        </tr>
        <tr>
          <td>UTS</td>
          <td><?= $nilai_uts !== null ? $nilai_uts : '-' ?></td>
          <td><?= $nilai_uts !== null ? round($nilai_uts * 0.3, 2) : '-' ?></td>
        </tr>
        <tr>
          <td>UAS</td>
          <td><?= $nilai_uas !== null ? $nilai_uas : '-' ?></td>
          <td><?= $nilai_uas !== null ? round($nilai_uas * 0.3, 2) : '-' ?></td>
        </tr>
        <tr class="table-primary">
          <th colspan="2" class="text-end"><strong>Nilai Akhir (dibulatkan)</strong></th>
          <th><strong>
            <?php
              $final = 0;
              if ($nilai_presensi !== null) $final += $nilai_presensi * 0.2;
              if ($nilai_tugas !== null) $final += $nilai_tugas * 0.2;
              if ($nilai_uts !== null) $final += $nilai_uts * 0.3;
              if ($nilai_uas !== null) $final += $nilai_uas * 0.3;
              echo round($final);
            ?>
          </strong></th>
        </tr>
      </tbody>
    </table>

    <div class="mt-3">
      <a href="/dashboard/mahasiswa-khs/detail?smt=<?= urlencode($smt) ?>" class="btn btn-secondary">Kembali ke KHS</a>
    </div>
  </div>
</div>
</br>
</br>
<?php include_once __DIR__ . '/../layouts/footer.php'; ?>
