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

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

<?= $this->section('page_title') ?>
    Dashboard ASN
<?= $this->endSection() ?>

<?= $this->section('content') ?>
<div class="row">
    <!-- Quick Actions -->
    <div class="col-lg-4">
        <div class="glass-card stat-card text-center bg-primary bg-opacity-25" style="border: 2px solid rgba(67, 97, 238, 0.4);">
            <h5 class="text-white small fw-bold mb-3">PILIHAN CEPAT</h5>
            <a href="<?= base_url('user/pengajuan') ?>" class="btn btn-primary d-block rounded-pill mb-2"><i class="bi bi-file-plus"></i> AJUKAN KENAIKAN PANGKAT</a>
            <a href="<?= base_url('user/riwayat') ?>" class="btn btn-outline-light d-block rounded-pill text-dark"><i class="bi bi-folder-open"></i> LIHAT BERKAS SAYA</a>
        </div>
    </div>
    
    <!-- Stats Row 1 -->
    <div class="col-lg-4">
        <div class="glass-card stat-card text-center">
            <h5 class="text-secondary small fw-bold text-uppercase">Total Pengajuan</h5>
            <h1 class="display-3 text-gradient"><?= $total_pengajuan ?></h1>
            <p class="text-muted small mb-0">Semua usulan Anda</p>
        </div>
    </div>
    <div class="col-lg-4">
        <div class="glass-card stat-card text-center" style="border-left: 5px solid #ffc107;">
            <h5 class="text-secondary small fw-bold text-uppercase">Menunggu Verifikasi</h5>
            <h1 class="display-3 text-warning"><?= $pending_pengajuan ?></h1>
            <p class="text-muted small mb-0">Sedang diperiksa Admin</p>
        </div>
    </div>
</div>

<div class="row mt-4">
    <!-- Stats Row 2 (SK Status) -->
    <div class="col-lg-6">
        <div class="glass-card stat-card text-center" style="border-left: 5px solid #fd7e14;">
            <div class="d-flex align-items-center justify-content-center gap-3">
                <i class="bi bi-hourglass-split fs-1 opacity-25"></i>
                <div class="text-start">
                    <h5 class="text-secondary small fw-bold text-uppercase mb-0">Menunggu SK</h5>
                    <h1 class="display-4 fw-bold mb-0" style="color: #fd7e14;"><?= $waiting_sk ?></h1>
                </div>
            </div>
            <p class="text-muted small mb-0 mt-2 text-start px-3">Usulan telah disetujui, sedang menunggu penerbitan fisik SK</p>
        </div>
    </div>
    <div class="col-lg-6">
        <div class="glass-card stat-card text-center" style="border-left: 5px solid #198754;">
            <div class="d-flex align-items-center justify-content-center gap-3">
                <i class="bi bi-patch-check-fill fs-1 opacity-25"></i>
                <div class="text-start">
                    <h5 class="text-secondary small fw-bold text-uppercase mb-0">SK Selesai</h5>
                    <h1 class="display-4 fw-bold mb-0" style="color: #198754;"><?= $sk_finish ?></h1>
                </div>
            </div>
            <p class="text-muted small mb-0 mt-2 text-start px-3">Selamat! SK Kenaikan Pangkat Anda telah terbit & selesai</p>
        </div>
    </div>
</div>

<div class="row mt-4">
    <div class="col-lg-12">
        <div class="glass-card" id="riwayat">
            <h4 class="mb-4">Riwayat Pengajuan Saya</h4>
            
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr class="text-secondary small fw-bold opacity-75">
                            <th>#ID</th>
                            <th>ASN / TARGET</th>
                            <th>JENIS KP</th>
                            <th>TANGGAL PENGAJUAN</th>
                            <th>STATUS</th>
                            <th>AKSI</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if(empty($history_pengajuan)): ?>
                            <tr>
                                <td colspan="6" class="text-center py-4 text-muted">Anda belum memiliki riwayat pengajuan.</td>
                            </tr>
                        <?php else: ?>
                            <?php foreach($history_pengajuan as $row): ?>
                                <tr>
                                    <td>#<?= $row['id'] ?></td>
                                    <td>
                                        <div class="fw-bold"><?= $row['target_nama'] ?></div>
                                        <span class="small text-muted"><?= $row['target_nip'] ?></span>
                                    </td>
                                    <td class="fw-bold"><?= $row['jenis_kp'] ?></td>
                                    <td><?= date('d M Y, H:i', strtotime($row['created_at'])) ?></td>
                                    <td>
                                        <?php if($row['status'] == 'PENDING'): ?>
                                            <span class="badge badge-status bg-warning text-dark">Ditinjau</span>
                                        <?php elseif($row['status'] == 'VERIFIED'): ?>
                                            <span class="badge badge-status bg-info text-white">Verifikasi OK</span>
                                        <?php elseif($row['status'] == 'REJECTED'): ?>
                                            <span class=""badge badge-status bg-danger text-white">Ditolak</span>
                                        <?php elseif($row['status'] == 'REVISION'): ?>
                                            <span class="badge badge-status bg-secondary text-white">Revisi</span>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <a href="#" class="btn btn-sm btn-outline-primary rounded-pill"><i class="bi bi-file-earmark-text"></i> Detail</a>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?= $this->endSection() ?>
