  <div class="content-wrapper">
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>User Admin</h1>            
          </div>          
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item active">List User Admin</li>
            </ol>
            <h3 class="card-title"></h3>
                
                    
          </div>
        </div>               
      </div><
      
    </section>

    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            
              <div class="card">
                <div class="card-header">
                  <button type="button" class="btn btn-success" data-toggle="modal" data-target="#modal-default">
                  Tambah Data
                  
                </div>
                <div class="card-body">
                  <table id="example1" class="table table-bordered table-striped">
                    <thead>
                      <tr>
                        <th>No</th>
                        <th>ID</th>
                        <th>user name</th>
                        <th>Nama</th>
                        <th>Role</th>
                        <th>Edit</th>
                        <th>Hapus</th>
                      </tr>
                      </thead>
                      <tbody>
             <?php
            include '../config/koneksi.php'; 
      $no = 1;
      $query = mysqli_query($conn, "SELECT users.user_id, users.username, roles.role_name, users.nama_lengkap, users.role_id FROM users JOIN roles ON users.role_id = roles.role_id;");
      while ($data = mysqli_fetch_array($query)) {  
          ?>
          <tr>
             <td><?= $no++ ?></td>
            <td><?= $data['user_id'] ?></td>
            <td><?= $data['username'] ?></td>
            <td><?= $data['nama_lengkap'] ?></td>
            <td><?= $data['role_name'] ?></td>

        <td>
            <button 
                type="button" 
                class="btn btn-primary" 
                data-toggle="modal" 
                data-target="#editAdmin" 
                data-id="<?= htmlspecialchars($data['user_id']) ?>" 
                data-nama="<?= htmlspecialchars($data['username']) ?>"
                data-namaPanjang="<?= htmlspecialchars($data['nama_lengkap']) ?>" 
                data-role="<?= htmlspecialchars($data['role_id']) ?>"
            >
                Edit
            </button>
        </td>


        <td>
          <a href="../config/hapusUser.php?user_id=<?= $data['user_id'] ?>" 
            onclick="return confirm('Yakin ingin menghapus?')" 
            class="btn btn-danger btn-sm">Hapus</a>
        </td>
      </tr>
        <?php } ?>


                      </tbody>

                  </table>
                  
              </div>
            
            </div>
           
          </div>
          
        </div>
      
      </div>
     
    </section>
   
  </div>
 


                  </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>
   </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>

  
 <div class="modal fade" id="modal-default">
  <div class="modal-dialog">
    <div class="modal-content bg-dark text-white">
    
      <div class="modal-header border-0">
        <h4 class="modal-title">Tambah Data</h4>
        <button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>

      <div class="modal-body">
        <?php include('formAdmin.php'); ?>
      </div>

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

 <div class="modal fade" id="editAdmin">
  <div class="modal-dialog">
    <div class="modal-content bg-dark text-white">
    
      <div class="modal-header border-0">
        <h4 class="modal-title">Edit Data</h4>
        <button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>

      <div class="modal-body">
        <?php include('editAdmin.php');?>
      </div>

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

<script>
window.onload = function() {
    const generatedText = Math.floor(Math.random() * 1000000);
    document.getElementById("id").value = generatedText;
}
</script>