<?= $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-clipboard-data me-2 text-primary"></i>Monitoring Jurnal Mengajar</h5>
        <p class="text-muted small mb-0">Pantau pelaksanaan pembelajaran guru.</p>
    </div>
    <form method="GET" class="d-flex align-items-center gap-2">
        <label class="text-muted small">Semester:</label>
        <select name="periode" class="form-select form-select-sm border-0 bg-light shadow-none" style="width:auto;" onchange="this.form.submit()">
            <?php foreach ($periods as $p): ?>
            <option value="<?= $p['id'] ?>" <?= $periodId == $p['id'] ? 'selected' : '' ?>>
                <?= esc($p['semester']) ?> <?= esc($p['academic_year_name'] ?? '') ?>
            </option>
            <?php endforeach; ?>
        </select>
    </form>
</div>

<div class="card shadow-sm border-0 rounded-3">
    <div class="card-body p-0">
        <?php if (empty($progress)): ?>
        <div class="text-center py-5 text-muted">
            <i class="bi bi-journal-text" style="font-size:2rem;"></i>
            <p class="mt-2 mb-0">Belum ada data jurnal untuk periode ini.</p>
        </div>
        <?php else: ?>
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="table-light">
                    <tr>
                        <th>Guru</th>
                        <th>Mapel</th>
                        <th>Kelas</th>
                        <th>Pertemuan</th>
                        <th class="text-center">Status</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($progress as $p): ?>
                    <?php
                    // Ambil target JP dari PROTA (bisa ditambahkan nanti)
                    $target = 24; // default, idealnya dari PROTA
                    $percent = $target > 0 ? round(($p['total_pertemuan'] / $target) * 100, 1) : 0;
                    $status = $percent >= 80 ? 'bg-success' : ($percent >= 50 ? 'bg-warning text-dark' : 'bg-danger');
                    $icon = $percent >= 80 ? 'bi-check-circle' : ($percent >= 50 ? 'bi-exclamation-triangle' : 'bi-x-circle');
                    ?>
                    <tr>
                        <td><?= esc($p['teacher_name']) ?></td>
                        <td><?= esc($p['subject_name']) ?></td>
                        <td><?= esc($p['classroom_name']) ?></td>
                        <td>
                            <div class="d-flex align-items-center gap-2">
                                <strong><?= $p['total_pertemuan'] ?></strong>
                                <small class="text-muted">/ <?= $target ?> JP</small>
                                <div class="progress" style="width:100px;height:6px;">
                                    <div class="progress-bar <?= $status ?>" role="progressbar"
                                         style="width:<?= min(100, $percent) ?>%;"></div>
                                </div>
                            </div>
                        </td>
                        <td class="text-center">
                            <span class="badge <?= $status ?>">
                                <i class="bi <?= $icon ?> me-1"></i><?= $percent ?>%
                            </span>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
        <?php endif; ?>
    </div>
</div>

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