<?php include_once __DIR__ . '/../layouts/head.php'; ?>
    <div class="container py-4" style="max-width: 1350px; width: 100%;">
      <div class="row">
        <div class="col-lg-12">
          <div class="shadow-sm bg-white rounded overflow-hidden border">
            <div class="p-0">
              <div class="row px-0 m-0">
			
				<?php include_once __DIR__ . '/../layouts/menu_body.php'; ?>
				
					<div class="col-12 col-md-9 px-0">
						<div class="tab-content" id="v-pills-tabContent">
						
							<!-- wates -->
							<div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">
								<div class="p-4">
									<div class="mb-4">
										<h5 class="mb-0 fw-bold">Validasi KHS Double</h5>
									</div>

                                    <?php if (isset($_SESSION['pesan']) && $_SESSION['pesan'] !== ''): ?>
                                        <div class="alert alert-info text-center fw-bold">
                                            <?= $_SESSION['pesan']; ?>
                                        </div>
                                        <?php $_SESSION['pesan'] = ''; ?>
                                    <?php endif; ?>
                                    
                                    <?php if (!empty($duplicates)): ?>
                                        <form method="POST">
                                            <div class="table-responsive">
                                                <table class="table table-bordered table-striped">
                                                    <thead class="table-dark text-center">
                                                        <tr>
                                                            <th><input class="form-check-input" type="checkbox" id="selectAll"></th>
                                                            <th>No</th>
                                                            <th>NIM</th>
                                                            <th>Nama</th>
                                                            <th>Kode MK</th>
                                                            <th>Semester</th>
                                                            <th>Nilai</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $no = 1; foreach ($duplicates as $row): ?>
                                                            <tr>
                                                                <td class="text-center">
                                                                    <input class="form-check-input checkItem" type="checkbox" name="id_khs[]" value="<?= htmlspecialchars($row['id_khs']); ?>">
                                                                </td>
                                                                <td class="text-center"><?= $no++; ?></td>
                                                                <td class="text-center"><?= htmlspecialchars($row['nim']); ?></td>
                                                                <td><?= htmlspecialchars($row['nama']); ?></td>
                                                                <td class="text-center"><?= htmlspecialchars($row['kode_mk']); ?></td>
                                                                <td class="text-center"><?= htmlspecialchars($row['smt']); ?></td>
                                                                <td class="text-center"><?= htmlspecialchars($row['nilai']); ?></td>
                                                            </tr>
                                                        <?php endforeach; ?>
                                                    </tbody>
                                                </table>
                                            </div>
                                            <div class="text-center mt-3">
                                                <button type="submit" name="hapus_massal" class="btn btn-danger btn-sm" onclick="return confirm('Apakah Anda yakin ingin menghapus data yang dipilih?');">Hapus Terpilih</button>
                                            </div>
                                        </form>
                                    
                                        <script>
                                            document.getElementById("selectAll").addEventListener("click", function() {
                                                document.querySelectorAll(".checkItem").forEach(cb => cb.checked = this.checked);
                                            });
                                        </script>
                                    <?php else: ?>
                                        <div class="alert alert-warning text-center">Tidak ada data KHS ganda ditemukan.</div>
                                    <?php endif; ?>

                                    
								</div>
							</div>
						</div>
					</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
	
<?php include_once __DIR__ . '/../layouts/footer.php'; ?>