<?= $this->extend('layout/management_layout') ?>
<?= $this->section('content') ?>

<div class="container-fluid">
    <div class="wrapper">
        <h2 class="text-center mt-4 mb-3">Schedule Parent Meeting</h2>

        <div class="card mx-auto" style="max-width: 720px;">
            <div class="card-body">
                <?php if (session()->getFlashdata('error')): ?>
                    <div class="alert alert-danger"><?= esc(session()->getFlashdata('error')) ?></div>
                <?php endif; ?>

                <form method="post" action="<?= site_url('grading/below-60/schedule') ?>">
                    <?= csrf_field() ?>
                    <input type="hidden" name="student_id" value="<?= esc((string)($studentId ?? 0)) ?>">
                    <input type="hidden" name="semester" value="<?= esc((string)($semester ?? '')) ?>">
                    <input type="hidden" name="school_year" value="<?= esc((string)($schoolYear ?? '')) ?>">

                    <div class="mb-2">
                        <strong>Student:</strong> <?= esc($studentName ?? 'Student') ?>
                    </div>
                    <div class="mb-2">
                        <strong>Parent:</strong> <?= esc($parentName ?? 'Parent/Guardian') ?>
                    </div>
                    <?php if (!empty($classSection)): ?>
                        <div class="mb-3">
                            <strong>Section:</strong> <?= esc($classSection) ?>
                        </div>
                    <?php endif; ?>

                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label">Date</label>
                            <input type="date" name="date" class="form-control" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">Time</label>
                            <input type="time" name="time" class="form-control">
                        </div>
                    </div>

                    <div class="mt-3">
                        <label class="form-label">Notes (optional)</label>
                        <textarea name="notes" class="form-control" rows="4"></textarea>
                    </div>

                    <div class="mt-4 d-flex justify-content-between">
                        <?php
                            $backQuery = http_build_query([
                                'semester' => (string)($semester ?? ''),
                                'school_year' => (string)($schoolYear ?? ''),
                            ]);
                        ?>
                        <a class="btn btn-outline-secondary" href="<?= base_url('grading/below-60') . ($backQuery ? ('?' . $backQuery) : '') ?>">Back</a>
                        <button type="submit" class="btn btn-primary">Create Meeting</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<?= $this->endSection() ?>
