<?php
include 'koneksi.php';
session_start();
if (!isset($_SESSION['login_admin'])) {
    header('Location: dashboard.php');
    exit;
}

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

if ($id_pengumuman <= 0) {
    echo "<script>alert('ID pengumuman tidak valid'); window.location.href='manage_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='manage_pengumuman.php';</script>";
    exit;
}

$row = mysqli_fetch_assoc($result);
$judul = htmlspecialchars($row['judul_pengumuman']);
$deskripsi = htmlspecialchars($row['deskripsi_pengumuman']);
$tanggal = date('d M Y H:i', 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_admin.css">
    <style>
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            font-family: 'Arial', sans-serif;
            margin: 0;
            padding: 0;
            min-height: 100vh;
        }
        .container {
            max-width: 900px;
            margin: 50px auto;
            padding: 30px;
            background: #fff;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        }
        .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, #0037fd, #5b8cffff);
            color: white;
            text-decoration: none;
            border-radius: 5px;
            transition: all 0.3s ease;
        }
        .back-button:hover {
            background: linear-gradient(135deg, #5b8cffff, #0037fd);
            transform: translateY(-2px);
        }
        .action-buttons {
            margin-top: 20px;
            text-align: center;
        }
        .edit-btn, .delete-btn {
            padding: 8px 15px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
            text-decoration: none;
            margin: 0 5px;
        }
        .edit-btn {
            background: #28a745;
            color: #fff;
        }
        .edit-btn:hover {
            background: #218838;
        }
        .delete-btn {
            background: #dc3545;
            color: #fff;
        }
        .delete-btn:hover {
            background: #c82333;
        }
    </style>
</head>
<body>
    <div class="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>

        <div class="action-buttons">
            <a href="edit_pengumuman.php?id=<?php echo $id_pengumuman; ?>" class="edit-btn">Edit</a>
            <a href="hapus_pengumuman.php?id=<?php echo $id_pengumuman; ?>" class="delete-btn" onclick="return confirm('Apakah Anda yakin ingin menghapus pengumuman ini?')">Hapus</a>
        </div>

        <a href="manage_pengumuman.php" class="back-button">← Kembali ke Kelola Pengumuman</a>
    </div>
</body>
</html>

