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

<?= $this->section('title') ?>
Admin Dashboard
<?= $this->endSection() ?>

<?= $this->section('page_title') ?>
Welcome, <?= session()->get('name') ?>
<?= $this->endSection() ?>

<?= $this->section('content') ?>
<div class="row">
    <!-- Stat Cards Row 1 -->
    <div class="col-md-3">
        <div class="glass-card stat-card text-center">
            <h5 class="text-secondary opacity-75 small fw-bold">TOTAL USER</h5>
            <h1 class="display-4 text-gradient"><?= $stats['total_user'] ?></h1>
            <p class="text-muted small mb-0 mt-2">Akun terdaftar</p>
        </div>
    </div>
    <div class="col-md-3">
        <div class="glass-card stat-card text-center" style="border-left: 5px solid #6c757d;">
            <h5 class="text-secondary opacity-75 small fw-bold">TOTAL PEGAWAI</h5>
            <h1 class="display-4" style="color: #6c757d;"><?= $stats['total_pegawai'] ?></h1>
            <p class="text-muted small mb-0 mt-2">Data di Master Pegawai</p>
        </div>
    </div>
    <div class="col-md-3">
        <div class="glass-card stat-card text-center" style="border-left: 5px solid #ffc107;">
            <h5 class="text-secondary opacity-75 small fw-bold">MENUNGGU VERIFIKASI</h5>
            <h1 class="display-4" style="color: #ffc107;"><?= $stats['pending'] ?></h1>
            <p class="text-muted small mb-0 mt-2">Perlu segera diproses</p>
        </div>
    </div>
    <div class="col-md-3">
        <div class="glass-card stat-card text-center" style="border-left: 5px solid #dc3545;">
            <h5 class="text-secondary opacity-75 small fw-bold">BERKAS DITOLAK</h5>
            <h1 class="display-4" style="color: #dc3545;"><?= $stats['rejected'] ?></h1>
            <p class="text-muted small mb-0 mt-2">Ditolak administratif</p>
        </div>
    </div>
</div>

<div class="row mt-4">
    <!-- Stat Cards Row 2 -->
    <div class="col-md-3">
        <div class="glass-card stat-card text-center" style="border-left: 5px solid #0dcaf0;">
            <h5 class="text-secondary opacity-75 small fw-bold">TERVERIFIKASI</h5>
            <h1 class="display-4" style="color: #0dcaf0;"><?= $stats['verified'] ?></h1>
            <p class="text-muted small mb-0 mt-2">Sedang Review Tim Penilai</p>
        </div>
    </div>
    <div class="col-md-3">
        <div class="glass-card stat-card text-center" style="border-left: 5px solid #fd7e14;">
            <h5 class="text-secondary opacity-75 small fw-bold">MENUNGGU SK</h5>
            <h1 class="display-4" style="color: #fd7e14;"><?= $stats['waiting_sk'] ?></h1>
            <p class="text-muted small mb-0 mt-2">Menunggu penerbitan SK</p>
        </div>
    </div>
    <div class="col-md-3">
        <div class="glass-card stat-card text-center" style="border-left: 5px solid #0d6efd;">
            <h5 class="text-secondary opacity-75 small fw-bold">DIPROSES (BKN)</h5>
            <h1 class="display-4" style="color: #0d6efd;"><?= $stats['process_bkn'] ?></h1>
            <p class="text-muted small mb-0 mt-2">Sedang divalidasi BKN</p>
        </div>
    </div>
    <div class="col-md-3">
        <div class="glass-card stat-card text-center" style="border-left: 5px solid #198754;">
            <h5 class="text-secondary opacity-75 small fw-bold">SK SELESAI</h5>
            <h1 class="display-4" style="color: #198754;"><?= $stats['sk_finish'] ?></h1>
            <p class="text-muted small mb-0 mt-2">SK telah terbit</p>
        </div>
    </div>
</div>

<div class="row mt-4">
    <div class="col-lg-12">
        <div class="glass-card">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h4 class="mb-0">Pengajuan Pangkat Terbaru</h4>
                <a href="#" class="btn btn-outline-primary btn-sm rounded-pill px-3">Lihat Semua</a>
            </div>

            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr class="text-secondary small fw-bold opacity-75">
                            <th>ID</th>
                            <th>NIP & NAMA</th>
                            <th>JENIS KP</th>
                            <th>TANGGAL</th>
                            <th>STATUS</th>
                            <th>AKSI</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if (empty($recent_pengajuan)): ?>
                            <tr>
                                <td colspan="6" class="text-center py-5 text-muted">Belum ada pengajuan masuk.</td>
                            </tr>
                        <?php else: ?>
                            <?php foreach ($recent_pengajuan as $row): ?>
                                <tr>
                                    <td>#<?= $row['id'] ?></td>
                                    <td>
                                        <div class="fw-bold"><?= $row['target_nama'] ?? 'Unknown' ?></div>
                                        <span class="small text-muted"><?= $row['target_nip'] ?? '-' ?></span>
                                    </td>
                                    <td><?= $row['jenis_kp'] ?></td>
                                    <td><?= date('d/m/Y', strtotime($row['created_at'])) ?></td>
                                    <td>
                                        <?php if ($row['status'] == 'PENDING'): ?>
                                            <span class="badge badge-status bg-warning text-dark">Pending</span>
                                        <?php elseif ($row['status'] == 'VERIFIED'): ?>
                                            <span class="badge badge-status bg-info text-white">Verified</span>
                                        <?php elseif ($row['status'] == 'REJECTED'): ?>
                                            <span class="badge badge-status bg-danger text-white">Rejected</span>
                                        <?php elseif ($row['status'] == 'REVISION'): ?>
                                            <span class="badge badge-status bg-secondary text-white">Revision</span>
                                        <?php elseif ($row['status'] == 'APPROVED'): ?>
                                            <span class="badge badge-status bg-success text-white">Approved</span>
                                        <?php elseif ($row['status'] == 'PROSES_BKN'): ?>
                                            <span class="badge badge-status bg-primary text-white">Proses BKN</span>
                                        <?php elseif ($row['status'] == 'PERTEK_BKN'): ?>
                                            <span class="badge badge-status bg-info text-dark">Pertek BKN</span>
                                        <?php elseif ($row['status'] == 'TOLAK_BKN'): ?>
                                            <span class="badge badge-status bg-danger text-white">Tolak BKN</span>
                                        <?php elseif ($row['status'] == 'WAITING_SK'): ?>
                                            <span class="badge badge-status bg-warning text-dark">Tunggu SK</span>
                                        <?php elseif ($row['status'] == 'SK_FINISH'): ?>
                                            <span class="badge badge-status bg-success text-white">SK Selesai</span>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <a href="<?= base_url('verifikator/detail/' . $row['id']) ?>"
                                            class="btn btn-sm btn-light rounded-pill"><i class="bi bi-eye"></i> Detail</a>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?= $this->endSection() ?>