<?php include 'koneksi.php';
$query = mysqli_query(
    $koneksi,
    "SELECT peminjam.*, buku.judul_buku 
FROM peminjam 
JOIN buku ON peminjam.id_buku = buku.id_buku"
);

while ($data = mysqli_fetch_array($query)) {
?>
    <div class="max-w-sm p-6 bg-gray-100 border border-gray-200 rounded-lg shadow-sm relative">
        <!-- Tombol Titik Tiga -->
        <div class="absolute right-2 top-2">
            <button id="dropdownButton-<?php echo $data['id_peminjam']; ?>" data-dropdown-toggle="dropdown-<?php echo $data['id_peminjam']; ?>" class="inline-block text-gray-500 hover:bg-gray-200 rounded-lg text-sm p-1.5" type="button">
                <svg class="w-6 h-6" aria-hidden="true" fill="currentColor" viewBox="0 0 20 20">
                    <path d="M6 10a2 2 0 11-4 0 2 2 0 014 0zM12 10a2 2 0 11-4 0 2 2 0 014 0zM16 12a2 2 0 100-4 2 2 0 000 4z" />
                </svg>
            </button>

            <!-- Dropdown Menu -->
            <div id="dropdown-<?php echo $data['id_peminjam']; ?>" class="hidden z-10 w-44 bg-white rounded divide-y divide-gray-100 shadow">
                <ul class="py-1 text-sm text-gray-700" aria-labelledby="dropdownButton-<?php echo $data['id_peminjam']; ?>">
                    <li>
                        <a data-modal-target="editpeminjam-<?php echo $data['id_peminjam']; ?>" data-modal-toggle="editpeminjam-<?php echo $data['id_peminjam']; ?>" class="block py-2 px-4 hover:bg-gray-100">Edit</a>
                    </li>
                    <li>
                        <a data-modal-target="detailpeminjam-<?php echo $data['id_peminjam']; ?>" data-modal-toggle="detailpeminjam-<?php echo $data['id_peminjam']; ?>" class="block py-2 px-4 hover:bg-gray-100 cursor-pointer">Detail</a>
                    </li>

                    <li>
                        <a onclick="confirmDelete(<?= $data['id_peminjam']; ?>)" class="block py-2 px-4 hover:bg-gray-100 text-red-600">Hapus</a>
                    </li>

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

        <!-- Konten Card -->
        <h5 class="mb-2 text-2xl font-semibold tracking-tight text-gray-900">Buku: <?php echo htmlspecialchars($data['judul_buku']) ?></h5>
        <p class="mb-3 font-normal text-gray-700">di pinjam oleh: <?php echo htmlspecialchars($data['nama_peminjam']) ?></p>
    </div>
<?php } ?>