<?php include 'header.php'; ?>

<?php
if (!isset($school) || !is_array($school) || !isset($school_id)) {
    // Jika data sekolah tidak valid, alihkan kembali untuk mencegah error
    $_SESSION['message'] = "Data sekolah tidak valid. Tidak dapat menampilkan formulir.";
    $_SESSION['message_type'] = "error";
    // Jika output sudah dikirim, kita tampilkan pesan error, bukan redirect
    echo '<div class="text-center p-10 bg-red-100">Data Sekolah Tidak Ditemukan. <a href="index.php">Kembali</a></div>';
    include 'footer.php';
    exit;
}
?>

<div class="mb-6">
    <a href="index.php?action=view_class&school_id=<?php echo $school_id; ?>" class="text-blue-600 hover:text-blue-800">&larr; Kembali</a>
</div>

<h2 class="text-2xl font-bold text-gray-800 mb-6">Tambah Kelas Baru di <?php echo htmlspecialchars($school['name']); ?></h2>

<form method="POST" action="index.php" class="space-y-4">
    <input type="hidden" name="school_id" value="<?php echo $school_id; ?>">
    
    <div>
        <label for="class_name" class="block text-sm font-medium text-gray-700">Nama Kelas</label>
        <input type="text" id="class_name" name="class_name" required class="mt-1 p-2 block w-full border-gray-300 rounded-md">
    </div>
    
    <div>
        <label for="kktp" class="block text-sm font-medium text-gray-700">KKM/KKTP</label>
        <input type="number" id="kktp" name="kktp" value="75" min="0" max="100" required class="mt-1 p-2 block w-full border-gray-300 rounded-md">
    </div>
    
    <div class="flex gap-4">
        <button type="submit" name="add_class" class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">Simpan</button>
        <a href="index.php?action=view_class&school_id=<?php echo $school_id; ?>" class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded text-center">Batal</a>
    </div>
</form>

<?php include 'footer.php'; ?>