<?= $this->extend('layout/management_layout') ?>
<?= $this->section('content') ?>
<div class="container-fluid">
    <div class="wrapper">
        <div class="content"></div>
                <h1>Course Materials</h1>
                <div class="mb-3">
                    <form action="/administrator/upload_material" method="post" enctype="multipart/form-data">
                        <div class="form-group">
                            <label for="materialTitle">Material Title</label>
                            <input type="text" class="form-control" id="materialTitle" name="title" required>
                        </div>
                        <div class="form-group">
                            <label for="materialFile">Upload File</label>
                            <input type="file" class="form-control" id="materialFile" name="file" required>
                        </div>
                        <button type="submit" class="btn btn-primary">Upload</button>
                    </form>
                </div>
                <h2>Uploaded Materials</h2>
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>Title</th>
                            <th>File</th>
                            <th>Uploaded At</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        // Example data - in a real scenario, this will be fetched from the database
                        $courseMaterials = [
                            ['title' => 'Lecture Notes 1', 'file' => 'lecture_notes_1.pdf', 'uploaded_at' => '2023-01-10'],
                            ['title' => 'Assignment 1', 'file' => 'assignment_1.pdf', 'uploaded_at' => '2023-01-12'],
                            // Add more materials as needed
                        ];

                        foreach ($courseMaterials as $material) {
                            echo "<tr>
                                    <td>{$material['title']}</td>
                                    <td><a href='/uploads/{$material['file']}' target='_blank'>{$material['file']}</a></td>
                                    <td>{$material['uploaded_at']}</td>
                                    <td>
                                        <a href='/administrator/delete_material/{$material['file']}' class='btn btn-danger btn-sm'>Delete</a>
                                    </td>
                                  </tr>";
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?= $this->endSection() ?>