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

<?= $this->section('title') ?>
Detail Pengajuan #
<?= $pengajuan['id'] ?>
<?= $this->endSection() ?>

<?= $this->section('page_title') ?>
Detail & Status Berkas Saya
<?= $this->endSection() ?>

<?= $this->section('content') ?>
<div class="row">
    <div class="col-lg-8">
        <div class="glass-card mb-4">
            <h4 class="mb-4">Informasi Pengajuan</h4>
            <div class="row">
                <div class="col-sm-6 mb-3">
                    <label class="small text-secondary fw-bold">SUBJECT PEGAWAI</label>
                    <p class="fw-bold h5 mb-1">
                        <?= $pengajuan['target_nama'] ?>
                    </p>
                    <code class="small"><?= $pengajuan['target_nip'] ?></code>
                </div>
                <div class="col-sm-6 mb-3">
                    <label class="small text-secondary fw-bold">JENIS KP</label>
                    <p class="fw-bold"><span class="badge bg-light text-dark rounded-pill border">
                            <?= $pengajuan['jenis_kp'] ?>
                        </span></p>
                </div>
                <div class="col-sm-6 mb-3">
                    <label class="small text-secondary fw-bold">TANGGAL PENGAJUAN</label>
                    <p class="fw-bold text-primary">
                        <?= date('d M Y, H:i', strtotime($pengajuan['created_at'])) ?>
                    </p>
                </div>
                <div class="col-sm-6 mb-3">
                    <label class="small text-secondary fw-bold">STATUS GLOBAL</label>
                    <div>
                        <?php if ($pengajuan['status'] == 'PENDING'): ?>
                            <span class="badge bg-warning text-dark px-3 py-2 rounded-pill">Ditinjau Verifikator</span>
                        <?php elseif ($pengajuan['status'] == 'VERIFIED'): ?>
                            <span class="badge bg-info text-white px-3 py-2 rounded-pill">Verifikasi OK</span>
                        <?php elseif ($pengajuan['status'] == 'REJECTED'): ?>
                            <span class="badge bg-danger text-white px-3 py-2 rounded-pill">Tolak / Tidak Valid</span>
                        <?php elseif ($pengajuan['status'] == 'REVISION'): ?>
                            <span class="badge bg-secondary text-white px-3 py-2 rounded-pill">Minta Revisi</span>
                        <?php elseif ($pengajuan['status'] == 'APPROVED'): ?>
                            <span class="badge bg-success text-white px-3 py-2 rounded-pill">Approve (Tim Penilai)</span>
                        <?php elseif ($pengajuan['status'] == 'PROSES_BKN'): ?>
                            <span class="badge bg-primary text-white px-3 py-2 rounded-pill">Proses BKN</span>
                        <?php elseif ($pengajuan['status'] == 'PERTEK_BKN'): ?>
                            <span class="badge bg-info text-dark px-3 py-2 rounded-pill">Pertek BKN</span>
                        <?php elseif ($pengajuan['status'] == 'TOLAK_BKN'): ?>
                            <span class="badge bg-danger text-white px-3 py-2 rounded-pill">Tolak BKN</span>
                        <?php elseif ($pengajuan['status'] == 'WAITING_SK'): ?>
                            <span class="badge bg-warning text-dark px-3 py-2 rounded-pill">Menunggu Penerbitan SK</span>
                        <?php elseif ($pengajuan['status'] == 'SK_FINISH'): ?>
                            <span class="badge bg-success text-white px-3 py-2 rounded-pill">SK Telah selesai di
                                cetak</span>
                        <?php endif; ?>
                    </div>
                </div>
            </div>

            <?php if (!empty($pengajuan['catatan_revisi'])): ?>
                <div class="alert alert-info border-0 rounded-4 mt-3" style="background-color: var(--card-bg);">
                    <label class="small fw-bold mb-1 d-block"><i class="bi bi-chat-dots-fill me-2"></i> CATATAN DARI
                        VERIFIKATOR:</label>
                    <p class="mb-0 fst-italic">"
                        <?= $pengajuan['catatan_revisi'] ?>"
                    </p>
                </div>
            <?php endif; ?>

            <hr class="my-4 opacity-10">
            <h5 class="mb-4">Daftar Dokumen & Respon Verifikator</h5>

            <?php if ($pengajuan['status'] == 'REVISION'): ?>
                <form action="<?= base_url('user/pengajuan/update/' . $pengajuan['id']) ?>" method="POST"
                    enctype="multipart/form-data">
                    <?= csrf_field() ?>
                <?php endif; ?>

                <div class="list-group list-group-flush">
                    <?php foreach ($dokumen as $doc): ?>
                        <div class="list-group-item bg-transparent border-0 px-0 mb-4 pb-3 border-bottom border-light">
                            <div class="d-flex justify-content-between align-items-start mb-2">
                                <div class="d-flex align-items-center gap-3">
                                    <div class="bg-danger bg-opacity-10 p-2 rounded-3">
                                        <i class="bi bi-file-earmark-pdf fs-4 text-danger"></i>
                                    </div>
                                    <div class="fw-bold text-uppercase small">
                                        <?= $doc['nama_dokumen'] ?>
                                    </div>
                                </div>
                                <div class="text-end">
                                    <?php if ($doc['status_verifikasi'] == 'OK'): ?>
                                        <span
                                            class="badge bg-success-subtle text-success border border-success border-opacity-25 rounded-pill px-3">Sesuai
                                            ✅</span>
                                    <?php elseif ($doc['status_verifikasi'] == 'REVISI'): ?>
                                        <span
                                            class="badge bg-warning-subtle text-warning border border-warning border-opacity-25 rounded-pill px-3">Revisi
                                            ⚠️</span>
                                    <?php elseif ($doc['status_verifikasi'] == 'REJECTED'): ?>
                                        <span
                                            class="badge bg-danger-subtle text-danger border border-danger border-opacity-25 rounded-pill px-3">Tolak
                                            ❌</span>
                                    <?php else: ?>
                                        <span class="badge bg-light text-muted border rounded-pill px-3">Menunggu</span>
                                    <?php endif; ?>
                                </div>
                            </div>

                            <?php if (!empty($doc['catatan'])): ?>
                                <div class="ms-5 mt-1 small bg-light p-2 rounded-3 border-start border-primary border-3">
                                    <span class="fw-bold text-primary">Respon:</span>
                                    <?= $doc['catatan'] ?>
                                </div>
                            <?php endif; ?>

                            <?php if ($pengajuan['status'] == 'REVISION' && ($doc['status_verifikasi'] == 'REVISI' || $doc['status_verifikasi'] == 'REJECTED')): ?>
                                <div class="ms-5 mt-3 p-3 rounded-4 bg-light border-dashed" style="border: 2px dashed #dee2e6;">
                                    <label class="small fw-bold text-dark mb-2 d-block"><i class="bi bi-cloud-upload me-1"></i>
                                        UPLOAD ULANG DOKUMEN (PDF, MAX 1MB):</label>
                                    <input type="file" name="dokumen[<?= $doc['id'] ?>]"
                                        class="form-control form-control-sm rounded-pill border-0 shadow-sm" accept=".pdf">
                                </div>
                            <?php endif; ?>
                        </div>
                    <?php endforeach; ?>
                </div>

                <?php if ($pengajuan['status'] == 'REVISION'): ?>
                    <div class="mt-4 text-center">
                        <button type="submit" class="btn btn-primary rounded-pill px-5 py-3 fw-bold shadow">
                            <i class="bi bi-send-check-fill me-2"></i> SIMPAN & KIRIM ULANG REVISI
                        </button>
                        <p class="small text-muted mt-2">Pastikan berkas yang Anda unggah sudah benar sebelum mengirim.</p>
                    </div>
                </form>
            <?php endif; ?>
        </div>
    </div>

    <div class="col-lg-4">
        <div class="glass-card text-center py-5">
            <?php if ($pengajuan['status'] == 'SK_FINISH' && !empty($pengajuan['sk_tte'])): ?>
                <i class="bi bi-check-circle-fill display-4 text-success opacity-50 mb-3 d-block"></i>
                <h5 class="text-success fw-bold">Selamat! SK Terbit</h5>
                <p class="small text-secondary px-3">SK Kenaikan Pangkat Anda telah selesai diproses dan ditandatangani
                    secara elektronik (TTE).</p>
                <a href="<?= base_url('uploads/sk_tte/' . $pengajuan['sk_tte']) ?>" target="_blank"
                    class="btn btn-success d-block w-100 rounded-pill px-4 mt-3 fw-bold shadow-lg">
                    <i class="bi bi-download me-2"></i> DOWNLOAD SK TTE
                </a>
            <?php else: ?>
                <i class="bi bi-info-circle-fill display-4 text-primary opacity-25 mb-3 d-block"></i>
                <h5>Panduan Status</h5>
                <p class="small text-secondary px-3">Update status usulan Anda akan tampil secara real-time di sini. Jika
                    status menunjukkan ⚠️ **Revisi**, harap segera perbaiki dokumen yang dimaksud.</p>
            <?php endif; ?>
            <?php if ($pengajuan['status'] == 'REVISION'): ?>
                <a href="<?= base_url('user/pengajuan/edit/' . $pengajuan['id']) ?>"
                    class="btn btn-warning d-block w-100 rounded-pill px-4 mt-3 fw-bold shadow-sm">
                    <i class="bi bi-pencil-square me-2"></i> PERBAIKI SEKARANG
                </a>
            <?php endif; ?>
            <a href="<?= base_url('user/riwayat') ?>" class="btn btn-light d-block w-100 rounded-pill px-4 mt-3">Kembali
                ke
                Riwayat</a>
        </div>
    </div>
</div>
<?= $this->endSection() ?>