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

$id_prestasi = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($id_prestasi <= 0) {
    header('Location: manage_prestasi.php');
    exit;
}

$query = "SELECT * FROM tb_prestasi WHERE id_prestasi = $id_prestasi";
$result = mysqli_query($host, $query);
if (!$result || mysqli_num_rows($result) == 0) {
    header('Location: manage_prestasi.php');
    exit;
}
$row = mysqli_fetch_assoc($result);
$nama_prestasi = htmlspecialchars($row['nama_prestasi']);
$deskripsi = htmlspecialchars($row['deskripsi']);
$kejuaraan_dari = htmlspecialchars($row['kejuaraan_dari']);
$gambar_prestasi = htmlspecialchars($row['gambar_prestasi']);
?>

<!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>Detail Prestasi | 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: 800px;
            margin: 50px auto;
            padding: 30px;
            background: #fff;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
            position: relative;
        }
        .container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 5px;
            background: linear-gradient(90deg, #0037fd, #5b8cffff);
            border-radius: 15px 15px 0 0;
        }
        h1 {
            text-align: center;
            color: #0037fd;
            margin-bottom: 30px;
            font-size: 28px;
            font-weight: bold;
        }
        .prestasi-image {
            text-align: center;
            margin-bottom: 20px;
        }
        .prestasi-image img {
            max-width: 100%;
            height: auto;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        .prestasi-details {
            margin-bottom: 30px;
        }
        .prestasi-details h2 {
            color: #333;
            margin-bottom: 10px;
            font-size: 24px;
        }
        .prestasi-details p {
            color: #666;
            line-height: 1.6;
            margin-bottom: 15px;
        }
        .kejuaraan {
            font-weight: bold;
            color: #b8860b;
        }
        .back-btn {
            background: linear-gradient(135deg, #0037fd, #5b8cffff);
            color: #fff;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            text-decoration: none;
            display: inline-block;
            transition: all 0.3s ease;
        }
        .back-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0,55,253,0.4);
        }
        .action-buttons {
            display: flex;
            gap: 10px;
            justify-content: center;
            margin-top: 20px;
        }
        .edit-btn, .delete-btn {
            padding: 8px 15px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
            text-decoration: none;
            transition: background-color 0.3s ease;
        }
        .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>
    <?php include 'navbar_admin.php'; ?>
    <div class="container">
        <h1>Detail Prestasi</h1>
        <div class="prestasi-image">
            <?php if (!empty($gambar_prestasi)): ?>
                <img src="upload/<?php echo $gambar_prestasi; ?>" alt="<?php echo $nama_prestasi; ?>">
            <?php else: ?>
                <img src="upload/default.jpg" alt="No Image">
            <?php endif; ?>
        </div>
        <div class="prestasi-details">
            <h2><?php echo $nama_prestasi; ?></h2>
            <p class="kejuaraan">Kejuaraan dari: <?php echo $kejuaraan_dari; ?></p>
            <p><?php echo nl2br($deskripsi); ?></p>
        </div>
        <div class="action-buttons">
            <a href="edit_prestasi.php?id=<?php echo $id_prestasi; ?>" class="edit-btn">Edit</a>
            <a href="hapus_prestasi.php?id=<?php echo $id_prestasi; ?>" class="delete-btn" onclick="return confirm('Apakah Anda yakin ingin menghapus prestasi ini?')">Hapus</a>
        </div>
        <div style="text-align: center; margin-top: 20px;">
            <a href="manage_prestasi.php" class="back-btn">Kembali ke Kelola Prestasi</a>
        </div>
    </div>
</body>
</html>

