<?php
include 'koneksi.php';

$id_pengumuman = isset($_GET['id']) ? intval($_GET['id']) : 0;

if ($id_pengumuman <= 0) {
    echo "<script>alert('ID pengumuman tidak valid'); window.location.href='pengumuman.php';</script>";
    exit;
}

$query = "SELECT * FROM tb_pengumuman WHERE id_pengumuman = $id_pengumuman";
$result = mysqli_query($host, $query);

if (!$result || mysqli_num_rows($result) == 0) {
    echo "<script>alert('Pengumuman tidak ditemukan'); window.location.href='pengumuman.php';</script>";
    exit;
}

$row = mysqli_fetch_assoc($result);
$judul = htmlspecialchars($row['judul_pengumuman']);
$deskripsi = htmlspecialchars($row['deskripsi_pengumuman']);
$tanggal = date('d M Y', strtotime($row['tanggal']));
$gambar = htmlspecialchars($row['gambar_pengumuman']);
?>
<!DOCTYPE html>
<html lang="en">
<head><link rel="icon" href="upload/bn2.png" type="image/png">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $judul; ?> | SMK Budiniah 2</title>
    <link rel="stylesheet" href="style.css">
    <style>
        body {
            font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
        }
        body a{
            cursor: pointer;
        }
        .navigasi {
            margin-bottom: 20px;
        }
        .head-kosong {
            width: 100%;
            background: #eef5ff;
            padding: 60px 0 120px;
            text-align: center;
            justify-content: center;
            justify-items: center;
        }
        .detail-container {
            margin: -80px auto 40px auto;
            background: #fff;
            padding: 30px;
            border-radius: 15px;
            max-width: 900px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        .detail-title {
            font-size: 32px;
            color: #333;
            margin-bottom: 10px;
            font-weight: bold;
        }
        .detail-date {
            color: #666;
            font-size: 14px;
            margin-bottom: 20px;
        }
        .detail-image {
            width: 100%;
            height: auto;
            object-fit: cover;
            border-radius: 8px;
            margin-bottom: 20px;
        }
        .detail-description {
            font-size: 18px;
            line-height: 1.6;
            color: #555;
            text-align: justify;
        }
        .back-button {
            display: inline-block;
            margin-top: 30px;
            padding: 10px 20px;
            background: linear-gradient(135deg, #0f62fe, #3f3ea5ff);
            color: white;
            text-decoration: none;
            border-radius: 5px;
            transition: all 0.3s ease;
        }
        .back-button:hover {
            background: linear-gradient(135deg, #3f3ea5ff, #0f62fe);
            transform: translateY(-2px);
        }
    </style>
</head>
<body>
    <div class="navigasi">
        <?php require "navbar.php"; ?>
    </div>
    <div class="head-kosong"></div>
    <div class="detail-container">
        <h1 class="detail-title"><?php echo $judul; ?></h1>
        <div class="detail-date"><?php echo $tanggal; ?></div>

        <?php if (!empty($gambar)): ?>
            <img src="upload/<?php echo $gambar; ?>" alt="<?php echo $judul; ?>" class="detail-image">
        <?php endif; ?>

        <div class="detail-description"><?php echo nl2br($deskripsi); ?></div>

        <a href="pengumuman.php" class="back-button">← Kembali ke Pengumuman</a>
    </div>

    <?php require "footer.php"; ?>
</body>
</html>

