<?php
    include "../backend/connection.php";
    $configure = new DefaultDatabase();
    $conf = $configure->connect();

    $districts = mysqli_query($conf,"SELECT * FROM districts");
    $schools = mysqli_query($conf, "SELECT * FROM schools");

?>
<div class="school-container">
    <h2>SCHOOLS MANAGEMENT</h2>
    <div class="add-school">
        <form method="POST">
            <input type="text" id="schoolName" placeholder="School Name" name="school_name" required>
            <select id="districtSelect" name="district" required>
                <option value="" disabled selected>Select District</option>
                <?php
                    while($dist = mysqli_fetch_array($districts))
                    {
                ?>
                <option value="<?php echo $dist["district_name"] ?>"><?php echo $dist["district_name"] ?></option>
                <?php
                    }
                ?>
            </select>
            <button  type="submit" name="register_school">Add School</button>
        </form>
    </div>
    <table id="schoolsTable">
        <thead>
            <tr>
                <th>School Name</th>
                <th>District</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            <!-- Dummy data -->
            <?php
                while($school = mysqli_fetch_array($schools))
                {
            ?>
            <tr>
                <td><?php echo $school["school_name"] ?></td>
                <td><?php echo $school["district"] ?></td>
                <td>
                <button class="delete"><a  href="./deletions/delete_school.php?school_del=<?php echo $school["id"] ?>" onclick="return confirm('Are you sure you want delete this school?');" style="color:white; text-decoration:none;">Delete</a></button>
                </td>
            </tr>
            <?php
                }
            ?>
        </tbody>
    </table>
</div>
