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

<?= $this->section('title') ?>
Riwayat Usul KP
<?= $this->endSection() ?>

<?= $this->section('page_title') ?>
Riwayat Usul Kenaikan Pangkat
<?= $this->endSection() ?>

<?= $this->section('content') ?>
<div class="row">
    <div class="col-lg-12">
        <div class="glass-card">
            <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 bg-warning text-dark px-3 py-2 rounded-pill">Ditinjau
                                                Verifikator</span>
                                        <?php elseif ($row['status'] == 'VERIFIED'): ?>
                                            <span class="badge bg-info text-white px-3 py-2 rounded-pill">Verifikasi OK</span>
                                        <?php elseif ($row['status'] == 'REJECTED'): ?>
                                            <span class="badge bg-danger text-white px-3 py-2 rounded-pill">Tolak / Tidak
                                                Valid</span>
                                        <?php elseif ($row['status'] == 'REVISION'): ?>
                                            <span class="badge bg-secondary text-white px-3 py-2 rounded-pill">Minta Revisi</span>
                                        <?php elseif ($row['status'] == 'APPROVED'): ?>
                                            <span class="badge bg-success text-white px-3 py-2 rounded-pill">Approve (Tim
                                                Penilai)</span>
                                        <?php elseif ($row['status'] == 'PROSES_BKN'): ?>
                                            <span class="badge bg-primary text-white px-3 py-2 rounded-pill">Proses BKN</span>
                                        <?php elseif ($row['status'] == 'PERTEK_BKN'): ?>
                                            <span class="badge bg-info text-dark px-3 py-2 rounded-pill">Pertek BKN</span>
                                        <?php elseif ($row['status'] == 'TOLAK_BKN'): ?>
                                            <span class="badge bg-danger text-white px-3 py-2 rounded-pill">Tolak BKN</span>
                                        <?php elseif ($row['status'] == 'WAITING_SK'): ?>
                                            <span class="badge bg-warning text-dark px-3 py-2 rounded-pill">Menunggu Penerbitan
                                                SK</span>
                                        <?php elseif ($row['status'] == 'SK_FINISH'): ?>
                                            <span class="badge bg-success text-white px-3 py-2 rounded-pill">SK Telah selesai di
                                                cetak</span>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <a href="<?= base_url('user/pengajuan/riwayat_detail/' . $row['id']) ?>"
                                            class="btn btn-sm btn-outline-primary rounded-pill px-3">
                                            <i class="bi bi-file-earmark-text me-1"></i> Detail
                                        </a>
                                        <?php if ($row['status'] == 'REVISION'): ?>
                                            <a href="<?= base_url('user/pengajuan/edit/' . $row['id']) ?>"
                                                class="btn btn-sm btn-warning rounded-pill px-3 ms-2 fw-bold text-dark border-0">
                                                <i class="bi bi-pencil-square me-1"></i> Perbaiki
                                            </a>
                                        <?php endif; ?>
                                        <?php if ($row['status'] == 'SK_FINISH' && !empty($row['sk_tte'])): ?>
                                            <a href="<?= base_url('uploads/sk_tte/' . $row['sk_tte']) ?>" target="_blank"
                                                class="btn btn-sm btn-success rounded-pill px-3 ms-2 fw-bold text-white border-0 shadow-sm">
                                                <i class="bi bi-download me-1"></i> Download SK TTE
                                            </a>
                                        <?php endif; ?>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?= $this->endSection() ?>