  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Produk</h1>            
          </div>          
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item active">List Produk</li>
            </ol>
          </div>
        </div>               
      </div><!-- /.container-fluid -->
      
    </section>

    <!-- Main content -->
     
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            
              <div class="card">
                <div class="card-header">
                  
                  <h3 class="card-title"></h3>
                 <button type="button" class="btn btn-success" data-toggle="modal" data-target="#modal-default">
                  Tambah Data
                </div>
                <!-- /.card-header -->
                <div class="card-body">
  <table id="example1" class="table table-bordered table-striped">
    <thead>
      <tr>
        <th>No</th>
        <th>ID</th>
        <th>Gambar</th>
        <th>Nama Produk</th>
        <th>Deskripsi</th>
        <th>Stok</th>
        <th>Harga</th>
        <th>Edit</th>
        <th>Hapus</th>
      </tr>
    </thead>
    <tbody>
            <?php
      include '../config/koneksi.php'; 
      $no = 1;
      $query = mysqli_query($conn, "SELECT * FROM products");
      while ($data = mysqli_fetch_array($query)) {
      ?>
      <tr>
        <td><?= $no++ ?></td>
        <td><?= $data['product_id'] ?></td>
        <td>
          <img src="data:image/jpeg;base64,<?= base64_encode($data['foto_produk']) ?>" width="60" height="60" style="object-fit: cover;">
        </td>
        <td><?= $data['nama_produk'] ?></td>
        <td><?= $data['deskripsi'] ?></td>
        <td><?= $data['stok'] ?></td>
        <td><?= $data['harga'] ?></td>

        <!-- Tombol Edit -->
        <td>
          <button 
            type="button" 
            class="btn btn-primary" 
            data-toggle="modal" 
            data-target="#editModal" 
            data-id="<?= $data['product_id']; ?>" 
            data-nama="<?= $data['nama_produk']; ?>"
            data-nama="<?= $data['nama_produk']; ?>" 
            data-deskripsi="<?= $data['deskripsi']; ?>"
            data-stok="<?= $data['stok']; ?>" 
            data-harga="<?= $data['harga']; ?>"
          >
            Edit
          </button>
        </td>

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



                      </tbody>

                  </table>
                  
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->


                  </table>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
   </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->


 <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('formproduk.php'); ?>
      </div>

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

 <div class="modal fade" id="editModal">
  <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('formedit.php');?>
      </div>

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



