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

<div class="card shadow-sm border-0 rounded-3">
    <div class="card-header bg-white py-3 border-0 d-flex align-items-center justify-content-between">
        <div>
            <h5 class="card-title fw-bold mb-0"><i class="bi bi-eye me-2 text-primary"></i>Detail Jurnal</h5>
            <p class="text-muted small mb-0">Informasi lengkap jurnal mengajar.</p>
        </div>
        <div class="d-flex gap-2">
            <a href="/guru/journal" class="btn btn-outline-secondary btn-sm">
                <i class="bi bi-arrow-left me-1"></i>Kembali
            </a>
        </div>
    </div>
    <div class="card-body p-4">
        <table class="table table-sm table-borderless" style="max-width:600px;">
            <tr>
                <td class="text-muted" style="width:120px;">Tanggal</td>
                <td>: <strong><?= date('d F Y', strtotime($j['meeting_date'])) ?></strong></td>
            </tr>
            <tr>
                <td class="text-muted">Jam ke-</td>
                <td>: <?= $j['start_period'] ?> – <?= $j['end_period'] ?></td>
            </tr>
            <tr>
                <td class="text-muted">Kelas</td>
                <td>: <?= esc($j['classroom_name']) ?></td>
            </tr>
            <tr>
                <td class="text-muted">Mapel</td>
                <td>: <?= esc($j['subject_name']) ?></td>
            </tr>
            <tr>
                <td class="text-muted">Pertemuan ke-</td>
                <td>: <?= $j['meeting_number'] ?></td>
            </tr>
            <tr>
                <td class="text-muted">Semester</td>
                <td>: <?= esc($j['semester']) ?> <?= esc($j['academic_year_name'] ?? '') ?></td>
            </tr>
        </table>

        <hr>
        <h6 class="fw-bold">Materi Pokok</h6>
        <p><?= esc($j['topic']) ?: '<span class="text-muted">—</span>' ?></p>


        <hr>
        <h6 class="fw-bold">Presensi</h6>
        <table class="table table-sm" style="max-width:400px;">
            <tr>
                <td>Hadir</td>
                <td><strong><?= $j['total_present'] ?></strong></td>
            </tr>
            <tr>
                <td>Sakit</td>
                <td><strong class="text-warning"><?= $j['total_sick'] ?></strong></td>
            </tr>
            <tr>
                <td>Izin</td>
                <td><strong class="text-info"><?= $j['total_permit'] ?></strong></td>
            </tr>
            <tr>
                <td>Alpha</td>
                <td><strong class="text-danger"><?= $j['total_absent'] ?></strong></td>
            </tr>
            <tr>
                <td>Jumlah siswa</td>
                <td><strong><?= $j['total_students'] ?></strong></td>
            </tr>
        </table>

        <?php if (!empty($absentees)): ?>
        <h6 class="fw-bold mt-3">Detail Siswa Tidak Hadir</h6>
        <table class="table table-sm table-bordered" style="max-width:500px;">
            <thead class="table-light">
                <tr><th>NISN</th><th>Nama</th><th>Status</th></tr>
            </thead>
            <tbody>
                <?php foreach ($absentees as $a): ?>
                <tr>
                    <td><code><?= esc($a['nisn']) ?></code></td>
                    <td><?= esc($a['full_name']) ?></td>
                    <td>
                        <?php if ($a['status'] === 'Sakit'): ?>
                        <span class="badge bg-warning text-dark">Sakit</span>
                        <?php elseif ($a['status'] === 'Izin'): ?>
                        <span class="badge bg-info">Izin</span>
                        <?php else: ?>
                        <span class="badge bg-danger">Alpha</span>
                        <?php endif; ?>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        <?php endif; ?>

        <?php if ($j['notes']): ?>
        <hr>
        <h6 class="fw-bold">Catatan / Kendala</h6>
        <p><?= esc($j['notes']) ?></p>
        <?php endif; ?>

        <?php if ($j['is_final']): ?>
        <hr>
        <span class="badge bg-success"><i class="bi bi-lock me-1"></i>Jurnal Final — Tidak bisa diedit</span>
        <?php endif; ?>
    </div>
</div>

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