<?php
include_once '../db/koneksi.php';

if (!isset($_SESSION['kode_admin'])) {
    echo '
      <script>
        alert("Terjadi kesalahan, harap masuk kembali!");
        window.location.replace("'.$alamat_admin.'keluar.php");
      </script>
    ';
    exit; // Pastikan skrip berhenti jika session tidak ada
}
?>

<div class="container-xxl flex-grow-1 container-p-y">
  <div class="row gy-4 mb-4">
    <div class="col-md-6">
      <div class="fw-bold fs-4 text-center text-md-start">Qris Otomatis</div>
    </div>
    <div class="card table-responsive p-3">
      <table class="table" id="example">
        <thead>
          <tr>
            <th scope="col" class="text-center">#</th>
            <th scope="col" class="text-center">UUID</th>
            <th scope="col" class="text-center">Aksi</th>
          </tr>
        </thead>
        <tbody>
          <?php
          $nomor_anggota = 1;
          $anggota = mysqli_query($koneksi, "SELECT * FROM tb_pga");

          if (mysqli_num_rows($anggota) > 0) {
              while ($data_anggota = mysqli_fetch_array($anggota)) {
                  $id = $data_anggota['id'];
                  $uuidpga = $data_anggota['uuid'];
          ?>
              <tr>
                <th scope="row" class="text-center"><?php echo $nomor_anggota++; ?></th>
                <td class="text-center"><?php echo htmlspecialchars($uuidpga); ?></td>
                <td class="text-center">
                  <a href="<?php echo htmlspecialchars($alamat_admin . 'ubah_uuid/' . $id); ?>" class="btn btn-sm btn-primary waves-effect waves-light">
                    <span class="tf-icons mdi mdi-pencil me-1"></span>
                    Ubah
                  </a>
                </td>
              </tr>
          <?php
              }
          } else {
          ?>
              <tr>
                <td class="text-center" colspan="7">Tidak Ada Data</td>
              </tr>
          <?php
          }
          ?>
        </tbody>
      </table>
    </div>
  </div>
</div>
