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

<div class="row g-3 mb-4">
    <div class="col-12">
        <div class="card border-0 shadow-sm">
            <div class="card-header bg-primary bg-opacity-10 text-primary py-3">
                <div class="d-flex align-items-center justify-content-between">
                    <div class="d-flex align-items-center gap-2">
                        <i class="bi bi-people-fill fs-4"></i>
                        <div>
                            <h5 class="mb-0 fw-bold">Daftar Siswa Kelas <?= esc($classroom['classroom_name']) ?></h5>
                            <small class="text-muted">Periode: <?= esc($activePeriod['year_name']) ?> &bull; Tingkat: <?= esc($classroom['grade_name']) ?></small>
                        </div>
                    </div>
                    <span class="badge bg-primary px-3 py-2 fs-6"><?= count($students) ?> Siswa</span>
                </div>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-striped table-hover align-middle table-sm" id="tableSiswa">
                        <thead>
                            <tr>
                                <th style="width: 50px;">Foto</th>
                                <th>NIS</th>
                                <th>NISN</th>
                                <th>Nama Lengkap</th>
                                <th>L/P</th>
                                <th>Telepon</th>
                                <th>Nama Ayah / Ibu</th>
                                <th>Alamat</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($students as $s): ?>
                            <tr>
                                <td>
                                    <?php if ($s['photo']): ?>
                                        <img src="<?= esc($s['photo_url']) ?>" alt="Foto" class="rounded" style="width:40px; height:45px; object-fit:cover;">
                                    <?php else: ?>
                                        <div class="bg-secondary bg-opacity-10 text-secondary rounded d-flex align-items-center justify-content-center fw-semibold text-center" style="width:40px; height:45px; font-size:10px;">
                                            No Photo
                                        </div>
                                    <?php endif; ?>
                                </td>
                                <td class="fw-semibold text-primary"><?= esc($s['nis']) ?></td>
                                <td class="text-muted"><?= esc($s['nisn'] ?: '-') ?></td>
                                <td class="fw-bold"><?= esc($s['full_name']) ?></td>
                                <td>
                                    <span class="badge bg-opacity-10 <?= $s['gender'] === 'L' ? 'bg-primary text-primary' : 'bg-danger text-danger' ?>">
                                        <?= $s['gender'] ?>
                                    </span>
                                </td>
                                <td><?= esc($s['phone'] ?: '-') ?></td>
                                <td>
                                    <div class="small fw-semibold"><?= esc($s['father_name'] ?: '-') ?></div>
                                    <div class="text-muted small"><?= esc($s['mother_name'] ?: '-') ?></div>
                                </td>
                                <td class="text-truncate" style="max-width: 200px;" title="<?= esc($s['address']) ?>">
                                    <?= esc($s['address'] ?: '-') ?>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

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

<?= $this->section('scripts') ?>
<script>
    $(document).ready(function() {
        $('#tableSiswa').DataTable({
            language: {
                url: 'https://cdn.datatables.net/plug-ins/1.13.8/i18n/id.json'
            },
            pageLength: 50,
            columnDefs: [
                { orderable: false, targets: 0 }
            ]
        });
    });
</script>
<?= $this->endSection() ?>
