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

$query = "SELECT * FROM tb_jurusan";
$result = mysqli_query($host, $query);
?>
<!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>Kelola Jurusan | 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: 1000px;
            margin: 50px auto;
            padding: 30px;
            background: #fff;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.2);
        }
        h1 {
            text-align: center;
            color: #0037fd;
            margin-bottom: 30px;
            font-size: 28px;
            font-weight: bold;
        }
        .top-buttons {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        .btn {
            background: linear-gradient(135deg, #0037fd, #5b8cffff);
            color: #fff;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
            font-weight: bold;
            text-decoration: none;
            transition: all 0.3s ease;
        }
        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(0,55,253,0.4);
        }
        .btn-secondary {
            background: #6c757d;
        }
        .btn-secondary:hover {
            background: #5a6268;
        }
        .jurusan-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 20px;
        }
        .jurusan-card {
            background: #f8f9fa;
            border-radius: 10px;
            padding: 20px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            transition: transform 0.3s ease;
        }
        .jurusan-card:hover {
            transform: translateY(-5px);
        }
        .jurusan-image {
            width: 300px;
            height: 300px;
            object-fit: cover;
            justify-content: center;
            justify-items: center;
            align-items: center;
            border-radius: 8px;
            margin-bottom: 15px;
        }
        .jurusan-name {
            font-size: 20px;
            font-weight: bold;
            color: #333;
            margin-bottom: 10px;
        }
        .jurusan-desc {
            color: #666;
            margin-bottom: 15px;
            line-height: 1.5;
        }
        .jurusan-actions {
            display: flex;
            gap: 10px;
        }
        .edit-btn, .delete-btn {
            padding: 5px 10px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 12px;
            text-decoration: none;
            transition: all 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;
        }
        .no-jurusan {
            text-align: center;
            color: #666;
            font-size: 18px;
            margin-top: 50px;
        }

        /* Responsive Design */
        @media (max-width: 768px) {
            .container {
                max-width: 95%;
                margin: 20px 20px 40px 15%;
                padding: 20px;
            }
            h1 {
                font-size: 24px;
                margin-bottom: 20px;
            }
            .top-buttons {
                position: static;
                justify-content: center;
                margin-bottom: 20px;
                gap: 20px;
            }
            .btn {
                padding: 12px 20px;
                font-size: 16px;
            }
            .jurusan-grid {
                grid-template-columns: 1fr;
                gap: 15px;
            }
            .jurusan-card {
                padding: 15px;
            }
            .jurusan-image {
                width: 100%;
                height: auto;
                margin-bottom: 10px;
            }
            .jurusan-name {
                font-size: 18px;
            }
            .jurusan-desc {
                font-size: 14px;
                margin-bottom: 10px;
            }
            .jurusan-actions {
                flex-direction: column;
                gap: 5px;
            }
            .edit-btn, .delete-btn {
                padding: 8px 15px;
                font-size: 14px;
            }
        }

        @media (min-width: 769px) and (max-width: 1024px) {
            .container {
                max-width: 90%;
                margin: 30px 20px 40px 10%;
                padding: 25px;
            }
            .jurusan-grid {
                grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
                gap: 18px;
            }
            .jurusan-image {
                width: 100%;
                height: auto;
            }
        }
    </style>
</head>
<body>
    <?php include 'navbar_admin.php'; ?>
    <div class="container">
        <h1>Kelola Jurusan</h1>
        <div class="top-buttons">
            <a href="tambah_jurusan.php" class="btn">Tambah Jurusan Baru</a>
            <button class="btn btn-secondary" onclick="toggleEditMode()">Mode Edit</button>
        </div>
        <div class="jurusan-grid">
            <?php
            if ($result && mysqli_num_rows($result) > 0) {
                while ($row = mysqli_fetch_assoc($result)) {
                    echo '<div class="jurusan-card">';
                    echo '<img src="upload/' . htmlspecialchars($row['gambar_jurusan']) . '" alt="' . htmlspecialchars($row['nama_jurusan']) . '" class="jurusan-image">';
                    echo '<div class="jurusan-name">' . htmlspecialchars($row['nama_jurusan']) . '</div>';
                    echo '<div class="jurusan-desc">' . htmlspecialchars($row['deksripsi']) . '</div>';
                    echo '<div class="jurusan-actions" style="display: none;">';
                    echo '<a href="edit_jurusan.php?id=' . $row['id_jurusan'] . '" class="edit-btn">Edit</a>';
                    echo '<a href="hapus_jurusan.php?id=' . $row['id_jurusan'] . '" class="delete-btn" onclick="return confirm(\'Apakah Anda yakin ingin menghapus jurusan ini?\')">Hapus</a>';
                    echo '</div>';
                    echo '</div>';
                }
            } else {
                echo '<div class="no-jurusan">Belum ada jurusan tersedia.</div>';
            }
            ?>
        </div>
    </div>
    <script>
        function toggleEditMode() {
            const actions = document.querySelectorAll('.jurusan-actions');
            actions.forEach(action => {
                action.style.display = action.style.display === 'none' ? 'flex' : 'none';
            });
        }
    </script>
</body>
</html>

