<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="d-flex align-items-center justify-content-between mb-4">
    <div>
        <h5 class="fw-bold mb-0"><i class="bi bi-journal-text me-2 text-primary"></i>Cetak Jurnal Kelas</h5>
        <p class="text-muted small mb-0">Cetak jurnal harian kelas terpadu per bulan</p>
    </div>
    <a href="/admin/kbm/rekap" class="btn btn-outline-secondary btn-sm">
        <i class="bi bi-arrow-left me-1"></i> Kembali ke Rekap
    </a>
</div>

<?php if (session()->getFlashdata('error')): ?>
<div class="alert alert-danger border-0 shadow-sm mb-4">
    <i class="bi bi-exclamation-circle-fill me-2"></i><?= session()->getFlashdata('error') ?>
</div>
<?php endif; ?>

<div class="row justify-content-center">
    <div class="col-md-6">
        <div class="card shadow-sm border-0 rounded-3">
            <div class="card-header bg-white py-3 border-0">
                <h6 class="card-title fw-bold mb-0 text-dark">Filter Jurnal Kelas</h6>
            </div>
            <div class="card-body p-4">
                <form action="/admin/kbm/jurnal-kelas/export" method="get" target="_blank">
                    
                    <!-- Pilih Kelas -->
                    <div class="mb-3">
                        <label class="form-label fw-semibold text-dark">Pilih Kelas</label>
                        <select name="classroom_id" class="form-select rounded-2" required>
                            <option value="">-- Pilih Kelas --</option>
                            <?php foreach ($classrooms as $c): ?>
                                <option value="<?= $c['id'] ?>"><?= esc($c['name']) ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>

                    <div class="row">
                        <!-- Pilih Bulan -->
                        <div class="col-md-6 mb-3">
                            <label class="form-label fw-semibold text-dark">Bulan</label>
                            <select name="month" class="form-select rounded-2" required>
                                <?php
                                $namaBulan = ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'];
                                $currentMonth = (int)date('m');
                                foreach ($namaBulan as $index => $name):
                                    $val = sprintf('%02d', $index + 1);
                                    $selected = ($index + 1 === $currentMonth) ? 'selected' : '';
                                ?>
                                    <option value="<?= $val ?>" <?= $selected ?>><?= $name ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>

                        <!-- Pilih Tahun -->
                        <div class="col-md-6 mb-4">
                            <label class="form-label fw-semibold text-dark">Tahun</label>
                            <select name="year" class="form-select rounded-2" required>
                                <?php
                                $currentYear = (int)date('Y');
                                for ($y = $currentYear - 2; $y <= $currentYear + 2; $y++):
                                    $selected = ($y === $currentYear) ? 'selected' : '';
                                ?>
                                    <option value="<?= $y ?>" <?= $selected ?>><?= $y ?></option>
                                <?php endfor; ?>
                            </select>
                        </div>
                    </div>

                    <!-- Submit Button -->
                    <button type="submit" class="btn btn-primary w-100 rounded-2 py-2 fw-semibold">
                        <i class="bi bi-printer me-1"></i> Preview & Cetak Jurnal
                    </button>
                </form>
            </div>
        </div>
    </div>
</div>

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