<main id="main" class="main">

  <div class="pagetitle">
    <h1>Whatsapp</h1>
    <nav>
      <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="index.php">Home</a></li>
        <li class="breadcrumb-item">Whatsapp</li>
      </ol>
    </nav>
  </div><!-- End Page Title -->

  <section class="section dashboard">
    <div class="card recent-sales overflow-auto">

      <div class="filter">
        <!-- Modal Dialog Scrollable -->
      </div>

      <div class="card-body">
        <h5 class="card-title">Whatsapp</h5>
        <?php
        if (isset($_GET['notif'])) {
          if ($_GET['notif'] == "berhasil_tambah_data") {
            echo '
                    <div class="alert alert-success" role="alert">
                        Berhasil menambahkan data.
                    </div>
                ';
          } else if ($_GET['notif'] == "berhasil_ubah_data") {
            echo '
                    <div class="alert alert-success" role="alert">
                        Berhasil mengubah data.
                    </div>
                ';
          } else if ($_GET['notif'] == "berhasil_hapus_data") {
            echo '
                    <div class="alert alert-success" role="alert">
                        Berhasil menghapus data.
                    </div>
                ';
          }
        }
        ?>

        <table class="table table-borderless datatable">
          <thead>
            <tr>
              <th scope="col">#</th>
              <th scope="col">No Whatsapp</th>
              <th scope="col">Aksi</th>
            </tr>
          </thead>
          <tbody>
            <?php
            $no = 1;
            $qry_voucher = mysqli_query($koneksi, "SELECT * FROM whatsapp");
            while ($dt_voucher = mysqli_fetch_array($qry_voucher)) {
              $id_whatsapp = $dt_voucher['id_whatsapp'];
              $nomor_whatsapp = $dt_voucher['nomor_whatsapp'];
              ?>
              <tr>
                <th><?php echo $no++; ?></th>
                <td><?php echo $nomor_whatsapp; ?></td>
                <td>
                  <button type="button" class="btn btn-sm btn-primary" data-bs-toggle="modal"
                    data-bs-target="#ubah_<?php echo $id_whatsapp; ?>"><i class="bi bi-pencil-square"></i></button>

                  <div class="modal fade" id="ubah_<?php echo $id_whatsapp; ?>" tabindex="-1">
                    <div class="modal-dialog">
                      <div class="modal-content">
                        <form action="prs_ubah_whatsapp.php" method="post">
                          <div class="modal-header">
                            <h5 class="modal-title">Ubah Data</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                          </div>
                          <div class="modal-body">
                            <input type="hidden" name="id_whatsapp" value="<?php echo $id_whatsapp; ?>">
                            <div class="form-floating mb-3">
                              <input type="text" class="form-control" id="nomor_whatsapp" name="nomor_whatsapp"
                                value="<?php echo $nomor_whatsapp; ?>">
                              <label for="nomor_whatsapp">No Whatsapp</label>
                            </div>
                          </div>
                          <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Batal</button>
                            <button type="submit" class="btn btn-primary">Ubah Data</button>
                          </div>
                        </form>
                      </div>
                    </div>
                  </div><!-- End Modal Dialog Scrollable-->
                </td>
              </tr>
            <?php } ?>
          </tbody>
        </table>

      </div>

    </div>
  </section>

</main><!-- End #main -->