<?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">
                <div class="tab-pane fade show active" id="v-pills-home">
                  <div class="p-4">
                    <div class="mb-4">
                      <h5 class="mb-0 fw-bold">Ubah Password Mahasiswa</h5>
                    </div>

                    <form class="mb-3" method="GET">
                      <div class="input-group">
                        <input type="text" class="form-control" name="search" placeholder="Cari mahasiswa..." value="<?= htmlspecialchars($_GET['search'] ?? '') ?>">
                        <button class="btn btn-outline-primary" type="submit">Search</button>
                      </div>
                    </form>

                    <?php if (!empty($_SESSION['pesan'])): ?>
                      <div class="alert alert-info"><?= $_SESSION['pesan']; ?></div>
                      <?php $_SESSION['pesan'] = ''; ?>
                    <?php endif; ?>

                    <table class="table table-bordered">
                      <thead>
                        <tr>
                          <th>No</th>
                          <th>Nama</th>
                          <th>NIM</th>
                          <th>Ubah Sandi</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php $no = 1; foreach ($mahasiswas as $mhs): ?>
                          <tr>
                            <td><?= $no++; ?></td>
                            <td><?= htmlspecialchars($mhs['nama']); ?></td>
                            <td><?= htmlspecialchars($mhs['username']); ?></td>
                            <td>
                              <form method="post" action="/dashboard/admin-ubah_pw_mahasiswa/reset">
                                <input type="hidden" name="id_user" value="<?= $mhs['id_user']; ?>">
                                <input type="hidden" name="password" value="mahasiswa">
                                <button class="btn btn-info text-white"><i class="bi bi-key"></i></button>
                              </form>
                            </td>
                          </tr>
                        <?php endforeach; ?>
                      </tbody>
                    </table>

                    <!-- Pagination -->
                    <nav>
                      <ul class="pagination justify-content-end">
                        <?php if ($currentPage > 1): ?>
                          <li class="page-item">
                            <a class="page-link" href="?page=<?= $currentPage - 1; ?>">Previous</a>
                          </li>
                        <?php endif; ?>
                        <?php for ($i = $startPage; $i <= $endPage; $i++): ?>
                          <li class="page-item <?= $i == $currentPage ? 'active' : ''; ?>">
                            <a class="page-link" href="?page=<?= $i; ?>"><?= $i; ?></a>
                          </li>
                        <?php endfor; ?>
                        <?php if ($currentPage < $totalPages): ?>
                          <li class="page-item">
                            <a class="page-link" href="?page=<?= $currentPage + 1; ?>">Next</a>
                          </li>
                        <?php endif; ?>
                      </ul>
                    </nav>

                  </div>
                </div>
              </div>
            </div>

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