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

// Get the teacher ID from URL parameter
$id_guru = isset($_GET['id']) ? intval($_GET['id']) : 0;

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

// Fetch teacher details from database
$query = "SELECT * FROM tb_guru WHERE id_guru = $id_guru";
$result = mysqli_query($host, $query);

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

$row = mysqli_fetch_assoc($result);
$nama_guru = htmlspecialchars($row['nama_guru']);
$jabatan = htmlspecialchars($row['jabatan']);
$matapelajaran = htmlspecialchars($row['matapelajaran']);
$gambar_guru = htmlspecialchars($row['gambar_guru']);
?>
<!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 $nama_guru; ?> | SMK Budiniah 2 Admin</title>
    <link rel="stylesheet" href="style_admin.css">
    <link rel="stylesheet" href="footer.css">
<style>
    *{
        margin: 0;
        padding: 0;
        scroll-behavior: smooth;
    }

    body{
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        background: #ffffff;
    }

    .guru-detail {
        width: 100%;
        background: #eef5ff;
        padding: 60px 0 120px;
        text-align: center;
    }

    .guru-detail h1 {
        font-size: 40px;
        font-weight: bold;
        color: #2a2a2a;
        text-transform: capitalize;
    }

    .detail-guru {
        margin: -80px auto 40px auto;
        background: #fff;
        padding: 30px;
        border-radius: 15px;
        max-width: 900px;

        display: grid;
        gap: 20px;

        box-shadow: 0 8px 20px rgba(0,0,0,0.12);
        position: relative;
        z-index: 10;
    }

    .bagian-teks {
        background: #fff;
        border-radius: 10px;
        line-height: 1.6;
    }

    .bagian-teks h3 {
        margin-bottom: 15px;
        color: #333;
    }

    .bagian-teks p {
        margin-bottom: 15px;
        text-align: justify;
    }

    .bagian-teks .jabatan {
        font-size: 18px;
        color: #666;
        margin-bottom: 20px;
        font-weight: bold;
    }

    .info-item {
        margin-bottom: 15px;
        font-size: 16px;
        color: #333;
    }

    .info-item strong {
        color: #0037fd;
        font-weight: bold;
    }

    .bagian-media {
        text-align: center;
        margin-bottom: 20px;
    }

    .bagian-media img {
        max-width: 300px;
        height: auto;
        border-radius: 10px;
    }

    .button-kembali {
        text-align: center;
        margin-top: 30px;
    }

    .button-kembali a {
        display: inline-block;
        padding: 10px 20px;
        background: linear-gradient(135deg, #0037fd, #5b8cffff);
        color: #fff;
        text-decoration: none;
        border-radius: 5px;
        font-weight: bold;
        transition: all 0.3s ease;
    }

    .button-kembali a:hover {
        transform: translateY(-2px);
        box-shadow: 0 5px 15px rgba(0,55,253,0.4);
    }

    @media (max-width: 768px) {
        .detail-guru {
            grid-template-columns: 1fr;
            margin: -50px 20px 20px 20px;
            padding: 20px;
        }
    }
</style>
</head>
<body>

<div class="guru-detail">
    <h1><?php echo $nama_guru; ?></h1>
</div>
<div class="detail-guru">
    <div class="bagian-media">
        <img src="upload/<?php echo !empty($gambar_guru) ? $gambar_guru : 'default.jpg'; ?>" alt="<?php echo $nama_guru; ?>" onerror="this.src='upload/default.jpg'">
</div>
    <div class="bagian-teks">
        <div class="info-item">
            <strong>Jabatan:</strong> <?php echo $jabatan; ?>
        </div>
        <div class="info-item">
            <strong>Mata Pelajaran:</strong> <?php echo $matapelajaran; ?>
        </div>
        <div class="button-kembali">
            <a href="manage_guru.php">← Kembali ke Kelola Guru</a>
        </div>
    </div>
</div>
</body>
</html>

