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

<div class="d-flex align-items-center justify-content-between mb-3">
    <div>
        <h5 class="fw-bold mb-0"><i class="bi bi-calendar-day me-2 text-primary"></i>KBM Hari Ini</h5>
        <p class="text-muted small mb-0">Pemantauan kegiatan belajar mengajar harian.</p>
    </div>
</div>

<!-- Filter -->
<div class="card shadow-sm border-0 rounded-3 mb-3">
    <div class="card-body p-3">
        <form method="GET" class="row g-2 align-items-end">
            <div class="col-md-3">
                <label class="form-label small mb-0">Tanggal</label>
                <input type="date" name="tanggal" class="form-control form-control-sm border-0 bg-light shadow-none"
                       value="<?= $tanggal ?>">
            </div>
            <div class="col-md-3">
                <label class="form-label small mb-0">Guru</label>
                <select name="guru" class="form-select form-select-sm border-0 bg-light shadow-none">
                    <option value="">Semua Guru</option>
                    <?php foreach ($semuaGuru as $g): ?>
                    <option value="<?= $g['id'] ?>" <?= $filterGuru == $g['id'] ? 'selected' : '' ?>>
                        <?= esc($g['name']) ?>
                    </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="col-md-3">
                <label class="form-label small mb-0">Kelas</label>
                <select name="kelas" class="form-select form-select-sm border-0 bg-light shadow-none">
                    <option value="">Semua Kelas</option>
                    <?php foreach ($semuaKelas as $k): ?>
                    <option value="<?= $k['id'] ?>" <?= $filterKelas == $k['id'] ? 'selected' : '' ?>>
                        <?= esc($k['name']) ?>
                    </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="col-md-3 d-flex align-items-end">
                <button class="btn btn-sm btn-outline-primary w-100"><i class="bi bi-funnel me-1"></i>Tampilkan</button>
            </div>
        </form>
    </div>
</div>

<!-- Jurnal Terisi -->
<div class="card shadow-sm border-0 rounded-3 mb-3">
    <div class="card-header bg-white py-3 border-0">
        <h6 class="card-title fw-bold mb-0">
            <i class="bi bi-check-circle text-success me-2"></i>Jurnal Terisi (<?= count($journals) ?>)
        </h6>
    </div>
    <div class="card-body p-0">
        <?php if (empty($journals)): ?>
        <div class="text-center py-4 text-muted">
            <i class="bi bi-journal-x" style="font-size:1.5rem;"></i>
            <p class="mt-2 small mb-0">Belum ada jurnal untuk tanggal ini.</p>
        </div>
        <?php else: ?>
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0 small">
                <thead class="table-light">
                    <tr>
                        <th>Guru</th>
                        <th>Mapel</th>
                        <th>Kelas</th>
                        <th>Jam</th>
                        <th>Materi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($journals as $j): ?>
                    <tr>
                        <td><?= esc($j['teacher_name']) ?></td>
                        <td><?= esc($j['subject_name']) ?></td>
                        <td><?= esc($j['classroom_name']) ?></td>
                        <td><?= $j['start_period'] ?>-<?= $j['end_period'] ?></td>
                        <td><?= esc($j['topic']) ?: '<span class="text-muted">—</span>' ?></td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <?php endif; ?>
    </div>
</div>

<!-- Guru Belum Isi -->
<div class="card shadow-sm border-0 rounded-3 border-warning">
    <div class="card-header bg-white py-3 border-0">
        <h6 class="card-title fw-bold mb-0 text-warning">
            <i class="bi bi-exclamation-triangle me-2"></i>Guru Belum Isi Jurnal (<?= count($guruBelum) ?>)
        </h6>
    </div>
    <div class="card-body p-0">
        <?php if (empty($guruBelum)): ?>
        <div class="text-center py-4 text-muted">
            <i class="bi bi-check-all" style="font-size:1.5rem;color:#10b981;"></i>
            <p class="mt-2 small mb-0">Semua guru sudah mengisi jurnal hari ini. ✅</p>
        </div>
        <?php else: ?>
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0 small">
                <thead class="table-light">
                    <tr>
                        <th>Guru</th>
                        <th>Kelas</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($guruBelum as $gb): ?>
                    <tr>
                        <td><?= esc($gb['name']) ?></td>
                        <td><?= esc($gb['classroom_name']) ?></td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <?php endif; ?>
    </div>
</div>

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