<?php include 'koneksi.php';
session_start();
if (!isset($_SESSION['login_admin'])) {
    header('Location: dashboard.php');
    exit;
}
?>
<!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 Ruang Kelas | 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);
            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;
        }
        .top-buttons {
            position: absolute;
            top: 20px;
            left: 30px;
            display: flex;
            gap: 10px;
        }
        .btn {
            background: linear-gradient(135deg, #0037fd, #5b8cffff);
            color: #fff;
            padding: 8px 15px;
            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);
        }
        .kelas-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 20px;
            margin-top: 60px;
        }
        .kelas-card {
            background: #fff;
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            transition: transform 0.3s ease;
        }
        .kelas-card:hover {
            transform: translateY(-5px);
        }
        .kelas-content {
            padding: 15px;
        }
        .kelas-content h3 {
            font-size: 18px;
            margin: 0 0 10px 0;
            text-transform: capitalize;
            color: #333;
        }
        .kelas-content p {
            font-size: 14px;
            color: #666;
            text-transform: capitalize;
            margin: 0 0 10px 0;
            line-height: 1.4;
        }
        .kelas-action {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .edit-btn, .delete-btn {
            padding: 5px 10px;
            border: none;
            border-radius: 10px;
            cursor: pointer;
            font-size: 12px;
            text-decoration: none;
            margin-left: 5px;
        }
        .edit-btn {
            background: #28a745;
            color: #fff;
        }
        .edit-btn:hover {
            background: #218838;
        }
        .delete-btn {
            background: #dc3545;
            color: #fff;
        }
        .delete-btn:hover {
            background: #c82333;
        }
        .no-kelas {
            text-align: center;
            color: #666;
            font-size: 18px;
            margin-top: 50px;
        }
        .action-buttons {
            display: none;
        }

        /* Responsive Design */
        @media (max-width: 1024px) {
            .container {
                max-width: 600px;
                margin: 20px 20px 40px 80px;
                padding: 20px;
            }
            h1 {
                font-size: 24px;
                margin-bottom: 20px;
            }
            .top-buttons {
                top: 15px;
                left: 20px;
                gap: 8px;
            }
            .btn {
                padding: 6px 12px;
                font-size: 13px;
            }
            .kelas-grid {
                grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
                gap: 15px;
                margin-top: 50px;
            }
            .kelas-content {
                padding: 12px;
            }
            .kelas-content h3 {
                font-size: 16px;
            }
            .kelas-content p {
                font-size: 13px;
            }
            .edit-btn, .delete-btn {
                padding: 4px 8px;
                font-size: 11px;
            }
            .top-buttons{
                position: static;
                justify-content: center;
                margin-bottom: 20px;
            }
        }

        @media (max-width: 768px) {
            .container {
                max-width: 600px;
                margin: 20px 20px 40px 80px;
                padding: 15px;
            }
            h1 {
                font-size: 20px;
                margin-bottom: 15px;
            }
            .top-buttons {
                position: static;
                justify-content: center;
                margin-bottom: 20px;
            }
            .btn {
                padding: 10px 15px;
                font-size: 14px;
            }
            .kelas-grid {
                grid-template-columns: 1fr;
                gap: 15px;
                margin-top: 20px;
            }
            .kelas-content {
                padding: 15px;
            }
            .kelas-content h3 {
                font-size: 18px;
            }
            .kelas-content p {
                font-size: 14px;
            }
            .edit-btn, .delete-btn {
                padding: 6px 12px;
                font-size: 12px;
                margin-left: 0;
                margin-right: 5px;
            }
            .kelas-action {
                flex-direction: column;
                align-items: flex-start;
                gap: 10px;
            }
            .no-kelas {
                font-size: 16px;
                margin-top: 30px;
            }
        }

        @media (max-width: 480px) {
            .container {
                max-width: 600px;
                margin: 20px 20px 40px 80px;
                padding: 10px;
            }
            h1 {
                font-size: 18px;
                margin-bottom: 10px;
            }
            .btn {
                padding: 8px 12px;
                font-size: 13px;
            }
            .kelas-content {
                padding: 10px;
            }
            .kelas-content h3 {
                font-size: 16px;
            }
            .kelas-content p {
                font-size: 13px;
            }
            .edit-btn, .delete-btn {
                padding: 5px 10px;
                font-size: 11px;
            }
            .top-buttons{
                position: static;
                justify-content: center;
                margin-bottom: 20px;
            }
            .no-kelas {
                font-size: 14px;
            }
        }
    </style>
</head>
<body>
    <?php include 'navbar_admin.php'; ?>
    <div class="container">
        <h1>Kelola Ruang Kelas</h1>
        <div class="top-buttons">
            <a href="tambah_ruangkelas.php" class="btn">Tambah Ruang Kelas</a>
            <button class="btn" onclick="toggleEditMode()">Edit Mode</button>
        </div>
        <div class="kelas-grid">
            <?php
            $query = "SELECT * FROM tb_ruang";
            $result = mysqli_query($host, $query);
            if ($result && mysqli_num_rows($result) > 0) {
                while ($row = mysqli_fetch_assoc($result)) {
                    $nama_kelas = htmlspecialchars($row['nama_ruang']);
                    $kapasitas = htmlspecialchars($row['kapasitas']);
                    $fasilitas = htmlspecialchars($row['fasilitas']);
                    $kelas = htmlspecialchars($row['kelas']);
                    echo '<div class="kelas-card">';
                    echo '<div class="kelas-content">';
                    echo "<h3>" . $nama_kelas . "</h3>";
                    echo '<p>Kelas: ' . $kelas . '</p>';
                    echo '<p>Kapasitas: ' . $kapasitas . ' siswa</p>';
                    echo '<p>Fasilitas: ' . $fasilitas . '</p>';
                    echo '<div class="kelas-action">';
                    echo '<div class="action-buttons">';
                    echo '<a href="edit_ruangkelas.php?id=' . $row['id_ruang'] . '" class="edit-btn">Edit</a>';
                    echo '<a href="hapus_ruangkelas.php?id=' . $row['id_ruang'] . '" class="delete-btn" onclick="return confirm(\'Apakah Anda yakin ingin menghapus ruang kelas ini?\')">Hapus</a>';
                    echo '</div>';
                    echo '</div>';
                    echo '</div>';
                    echo '</div>';
                }
            } else {
                echo '<div class="no-kelas">Belum ada ruang kelas tersedia.</div>';
            }
            ?>
        </div>
    </div>
    <script>
        function toggleEditMode() {
            const actionButtons = document.querySelectorAll('.action-buttons');
            actionButtons.forEach(btn => {
                btn.style.display = btn.style.display === 'none' ? 'block' : 'none';
            });
        }
    </script>
</body>
</html>

