<aside class="control-sidebar control-sidebar-dark">
</aside>
</div>
<script src="../asset/plugins/jquery/jquery.min.js"></script>
<script src="../asset/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>

<script src="../asset/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../asset/plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../asset/plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../asset/plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="../asset/plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="../asset/plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="../asset/plugins/jszip/jszip.min.js"></script>
<script src="../asset/plugins/pdfmake/pdfmake.min.js"></script>
<script src="../asset/plugins/pdfmake/vfs_fonts.js"></script>
<script src="../asset/plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="../asset/plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="../asset/plugins/datatables-buttons/js/buttons.colVis.min.js"></script>
<script src="../js/bootstrap.bundle.min.js"></script>

<script src="../asset/dist/js/adminlte.min.js"></script>
<script src="../asset/dist/js/demo.js"></script>

<script>
$(document).ready(function() {
    $("#example1").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');

    $('#example2').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });

    $('.deleteBtn').click(function() {
        var id = $(this).data('id');
        if (confirm("Yakin ingin menghapus produk ini?")) {
            $.ajax({
                url: 'hapus_produk.php',
                type: 'POST',
                data: { id_produk: id },
                success: function(response) {
                    if (response.trim() === "Sukses") {
                        alert("Produk berhasil dihapus!");
                        location.reload();
                    } else {
                        alert("Gagal menghapus produk.");
                    }
                },
                error: function() {
                    alert("Terjadi kesalahan saat menghapus.");
                }
            });
        }
    });
});

$('#editModal').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget); 
    var id = button.data('id');
    var nama = button.data('nama');
    var deskripsi = button.data('deskripsi');
    var stok = button.data('stok');
    var harga = button.data('harga');

    var modal = $(this);
    modal.find('#edit_id').val(id);
    modal.find('#edit_nama').val(nama);
    modal.find('#edit_deskripsi').val(deskripsi);
    modal.find('#edit_stok').val(stok);
    modal.find('#edit_harga').val(harga);

    modal.find('input[name="gambar"]').val('')
});


$('#editAdmin').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget); 
    var id = button.data('id');
    var username = button.data('nama'); 
    var namaPanjang = button.data('namapanjang'); 
    var role = button.data('role'); 
    
    var modal = $(this);
    modal.find('#edit_id_user').val(id);
    modal.find('#edit_username_user').val(username);
    modal.find('#edit_nama_user').val(namaPanjang);
    modal.find('#edit_role_user').val(role);
    
    modal.find('#edit_password_user').val('');    
});

$('#editMembership').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget); 
    var id = button.data('id');
    var nama = button.data('nama');
    var durasi = button.data('durasi'); 
    var harga = button.data('harga');
    var deskripsi = button.data('deskripsi');
    
    var modal = $(this);

    var durasiValue = durasi.split(' ')[0];
    var durasiUnit = durasi.split(' ')[1];

    modal.find('#edit_package_id').val(id);
    modal.find('#edit_package_name').val(nama);
    modal.find('#edit_durationValue').val(durasiValue);
    modal.find('#edit_durationUnit').val(durasiUnit);
    modal.find('#edit_price').val(harga);
    modal.find('#edit_description').val(deskripsi);
});


</script>

</body>
</html>
