<?php 
// Security Headers
header("X-Frame-Options: SAMEORIGIN"); // cegah clickjacking
header("X-Content-Type-Options: nosniff"); // cegah MIME sniffing
header("X-XSS-Protection: 1; mode=block"); // cegah XSS di browser lama
header("Referrer-Policy: no-referrer-when-downgrade"); // batasi info referrer
header("Content-Security-Policy: default-src 'self' https: data:; script-src 'self' https://cdn.jsdelivr.net https://cdnjs.cloudflare.com; style-src 'self' https://cdn.jsdelivr.net https://fonts.googleapis.com 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' https://fonts.gstatic.com;"); 
?>

<?php
include 'header.php';
include 'config.php';

$id = $_GET['id'] ?? 0;
$data = $conn->query("SELECT * FROM buku WHERE id='$id'");
if ($data->num_rows == 0) {
    echo "<div class='alert alert-danger'>Buku tidak ditemukan.</div>";
    include 'footer.php';
    exit;
}
$buku = $data->fetch_assoc();
?>

<div class="row g-4">
    <!-- Cover Buku -->
    <div class="col-md-4">
        <img src="admin/uploads/<?= $buku['cover'] ?>" class="img-fluid rounded shadow-sm" alt="<?= htmlspecialchars($buku['judul']) ?>">
    </div>

    <!-- Detail Buku -->
    <div class="col-md-8">
        <h2><?= htmlspecialchars($buku['judul']) ?></h2>
        <ul class="list-group mb-3">
            <li class="list-group-item"><strong>Penulis:</strong> <?= htmlspecialchars($buku['penulis']) ?></li>
            <li class="list-group-item"><strong>Tahun Terbit:</strong> <?= $buku['tahun'] ?></li>
            <li class="list-group-item"><strong>Jumlah Halaman:</strong> <?= $buku['halaman'] ?></li>
            <li class="list-group-item"><strong>Jenis Buku:</strong> <?= $buku['jenis'] ?></li>
            <li class="list-group-item"><strong>Ukuran Buku:</strong> <?= htmlspecialchars($buku['ukuran']) ?></li>
            <li class="list-group-item"><strong>ISBN:</strong> <?= htmlspecialchars($buku['isbn']) ?></li>
            <li class="list-group-item"><strong>Edisi:</strong> <?= htmlspecialchars($buku['edisi']) ?></li>
            <li class="list-group-item"><strong>Stok:</strong> <?= $buku['stock'] ?> pcs</li>
            <li class="list-group-item"><strong>Harga:</strong> Rp <?= number_format($buku['harga'], 0, ',', '.') ?></li>
        </ul>

        <h5>Deskripsi / Sinopsis</h5>
        <p style="text-align:justify;"><?= nl2br(htmlspecialchars($buku['deskripsi'])) ?></p>

        <!-- Tombol WA -->
        <?php
        $nomor_wa = "6289512582226";
        $pesan     = "Halo, apakah saya dapat membeli buku ini (" . $buku['judul'] . ")";
        ?>
        <a href="https://wa.me/<?= $nomor_wa ?>?text=<?= urlencode($pesan) ?>" class="btn btn-success mt-2" target="_blank">
            Hubungi via WhatsApp
        </a>
        <a href="katalog.php" class="btn btn-secondary mt-2">Kembali</a>
    </div>
    
</div>


<?php include 'footer.php'; ?>
