<?php include('partials/template.php'); ?>
<?php include('partials/sidebar.php'); 
?>

<div class="p-4 sm:ml-64">
   <div class="p-4 border-gray-200">
      <div class="container grid gap-4">
         <div class="flex justify-between items-center">
            <a href="index.php"><img class="h-8" src="assets/BOOKRENT.svg" alt="BOOKRENT"></a>
            <img src="assets/user.png" alt="User Photo" class="w-10 h-10 rounded-full border border-gray-300 shadow-sm">
         </div>

         <div class="grid grid-cols-4 gap-4 mt-5   ">
            <?php 
            include('partials/peminjam.php'); 
            include('peminjam/detail.php');
            include('peminjam/edit.php'); 
            ?>
         </div>
      </div>
   </div>
</div>

<?php
if (isset($_GET['alert'])) {
    $alert = $_GET['alert'];
    
    echo "<script>";
    switch ($alert) {
        case "Berhasil":
            echo "Swal.fire('Berhasil!', 'Data peminjam berhasil ditambahkan!', 'success');";
            break;
        case "gagal":
            echo "Swal.fire('Gagal!', 'Terjadi kesalahan saat menyimpan data!', 'error');";
            break;
        case "hapus_berhasil":
            echo "Swal.fire('Dihapus!', 'Data peminjam telah dihapus!', 'success');";
            break;
        case "hapus_gagal":
            echo "Swal.fire('Gagal!', 'Tidak dapat menghapus data peminjam!', 'error');";
            break;

        case "akses_tidak_sah":
            echo "Swal.fire('Peringatan!', 'Akses tidak sah!', 'warning');";
            break;
    }
    echo "</script>";
}
?>

<script>
function confirmDelete(id) {
    Swal.fire({
        title: "Apakah Anda yakin?",
        text: "Data peminjam yang dihapus tidak bisa dikembalikan!",
        icon: "warning",
        showCancelButton: true,
        confirmButtonColor: "#d33",
        cancelButtonColor: "#3085d6",
        confirmButtonText: "Ya, hapus!",
        cancelButtonText: "Batal"
    }).then((result) => {
        if (result.isConfirmed) {
            window.location.href = "peminjam/hapus.php?id=" + id;
        }
    });
}
</script>

