<?= $this->extend('layout/admin') ?>
<?= $this->section('content') ?>

<style>
.page-wrapper{
    background:linear-gradient(to bottom,#eef3ff,#ffffff);
    padding:15px;
    border-radius:10px
}
.card-premium{
    border-radius:18px;
    border:0;
    overflow:hidden
}
.header-box{
    background:linear-gradient(135deg,#1f3bb3,#4e7bff);
    color:#fff;
    padding:22px;
}
.header-box h4{
    font-weight:900;
    letter-spacing:.5px
}
.stat-box{
    border-radius:14px;
    padding:20px;
    color:#fff;
}
.stat-title{
    font-size:13px;
    opacity:.9
}
.stat-value{
    font-size:32px;
    font-weight:900
}
.table-ranking{
    border-radius:12px;
    overflow:hidden
}
</style>

<div class="page-wrapper">

    <div class="card card-premium shadow-sm">

        <div class="header-box">
            <div class="d-flex justify-content-between">
                <div>
                    <h4>📊 Dashboard Hasil Seleksi PPDB</h4>
                    <small class="opacity-75">
                        Monitoring realtime — versi enterprise premium
                    </small>
                </div>

                <a href="<?= site_url('ppdb/admin') ?>" class="btn btn-light">
                    <i class="fas fa-arrow-left me-1"></i> Kembali
                </a>
            </div>
        </div>

        <div class="card-body">

            <!-- STAT BOX -->
            <div class="row text-white">

                <div class="col-md-3 mb-3">
                    <div class="stat-box" style="background:#2d6cdf">
                        <div class="stat-title">TOTAL PENDAFTAR</div>
                        <div class="stat-value"><?= $total ?></div>
                    </div>
                </div>

                <div class="col-md-3 mb-3">
                    <div class="stat-box" style="background:#28a745">
                        <div class="stat-title">DITERIMA</div>
                        <div class="stat-value"><?= $approved ?></div>
                    </div>
                </div>

                <div class="col-md-3 mb-3">
                    <div class="stat-box" style="background:#ffc107; color:#000">
                        <div class="stat-title">PROSES</div>
                        <div class="stat-value"><?= $pending ?></div>
                    </div>
                </div>

                <div class="col-md-3 mb-3">
                    <div class="stat-box" style="background:#dc3545">
                        <div class="stat-title">DITOLAK</div>
                        <div class="stat-value"><?= $rejected ?></div>
                    </div>
                </div>

            </div>

            <hr>

            <!-- Ranking Section -->
            <div class="table-ranking shadow-sm">
                <div class="p-2 bg-primary text-white fw-bold">
                    <i class="fas fa-trophy me-2"></i> Ranking Seleksi
                </div>

                <table class="table table-bordered mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>Rank</th>
                            <th>No Daftar</th>
                            <th>Nama</th>
                            <th>NISN</th>
                            <th>Nilai / Skor</th>
                            <th>Status</th>
                        </tr>
                    </thead>

                    <tbody>
                        <?php $no=1; foreach($rank as $r): ?>
                        <tr>
                            <td><b><?= $no++ ?></b></td>
                            <td><?= $r['reg_no'] ?></td>
                            <td><?= $r['name'] ?></td>
                            <td><?= $r['nisn'] ?></td>

                            <td>
                                <span class="badge bg-dark">
                                    <?= $r['score'] ?? '-' ?>
                                </span>
                            </td>

                            <td>
                                <?php 
                                    $cls = 'secondary';
                                    if($r['status']=="APPROVED") $cls="success";
                                    if($r['status']=="PENDING") $cls="warning";
                                    if($r['status']=="REJECTED") $cls="danger";
                                ?>
                                <span class="badge bg-<?= $cls ?> fw-bold">
                                    <?= $r['status'] ?>
                                </span>
                            </td>
                        </tr>
                        <?php endforeach ?>
                    </tbody>
                </table>

            </div>

        </div>

    </div>

</div>

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