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

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

<?= $this->section('page_title') ?>
Perbaikan Dokumen Kenaikan Pangkat
<?= $this->endSection() ?>

<?= $this->section('content') ?>
<div class="row justify-content-center">
    <div class="col-lg-10">
        <form action="<?= base_url('user/pengajuan/update/' . $pengajuan['id']) ?>" method="POST"
            enctype="multipart/form-data">
            <?= csrf_field() ?>

            <div class="glass-card mb-4">
                <div class="d-flex align-items-center mb-4 border-bottom pb-3">
                    <div class="bg-warning bg-opacity-10 p-3 rounded-4 me-3">
                        <i class="bi bi-pencil-square text-warning fs-3"></i>
                    </div>
                    <div>
                        <h5 class="fw-bold mb-1">Status Usulan: BUTUH REVISI</h5>
                        <p class="text-muted small mb-0">Silakan perbaiki dokumen yang ditandai ⚠️ atau perbarui
                            informasi yang diminta.</p>
                    </div>
                </div>

                <div class="alert alert-warning border-0 rounded-4 px-4 py-3 mb-4">
                    <div class="fw-bold mb-1"><i class="bi bi-info-circle-fill me-2"></i> CATATAN VERIFIKATOR:</div>
                    <div class="fst-italic">"
                        <?= $pengajuan['catatan_revisi'] ?>"
                    </div>
                </div>

                <div class="row g-4">
                    <div class="col-md-6">
                        <label class="form-label-custom">SUBJEK PEGAWAI</label>
                        <input type="text" class="form-control rounded-pill bg-light"
                            value="<?= $pengajuan['target_nip'] ?> - <?= $pengajuan['target_nama'] ?>" disabled>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label-custom">JENIS KP</label>
                        <input type="text" class="form-control rounded-pill bg-light" name="jenis_kp"
                            value="<?= $pengajuan['jenis_kp'] ?>">
                    </div>
                </div>
            </div>

            <h4 class="mb-4 ps-2"><i class="bi bi-cloud-arrow-up-fill text-primary"></i> Daftar Dokumen & Perbaikan</h4>
            <div class="row g-4">
                <?php foreach ($dokumen as $doc): ?>
                    <div class="col-12">
                        <div
                            class="glass-card <?= ($doc['status_verifikasi'] == 'REVISI' || $doc['status_verifikasi'] == 'REJECTED') ? 'border border-warning' : '' ?>">
                            <div class="d-flex justify-content-between align-items-start mb-3">
                                <div class="d-flex align-items-center gap-3">
                                    <div
                                        class="<?= ($doc['status_verifikasi'] == 'REVISI') ? 'bg-warning' : 'bg-primary' ?> bg-opacity-10 p-2 rounded-3">
                                        <i
                                            class="bi bi-file-earmark-pdf fs-4 <?= ($doc['status_verifikasi'] == 'REVISI') ? 'text-warning' : 'text-primary' ?>"></i>
                                    </div>
                                    <div>
                                        <div class="fw-bold text-uppercase small">
                                            <?= $doc['nama_dokumen'] ?>
                                        </div>
                                        <a href="<?= base_url('uploads/dokumen/' . $doc['file_path']) ?>" target="_blank"
                                            class="small text-muted text-decoration-none">
                                            <i class="bi bi-link-45deg"></i> Lihat Berkas Saat Ini
                                        </a>
                                    </div>
                                </div>
                                <div class="text-end">
                                    <?php if ($doc['status_verifikasi'] == 'OK'): ?>
                                        <span
                                            class="badge bg-success bg-opacity-10 text-success border border-success border-opacity-10 rounded-pill px-3">Sudah
                                            Sesuai ✅</span>
                                    <?php elseif ($doc['status_verifikasi'] == 'REVISI'): ?>
                                        <span
                                            class="badge bg-warning bg-opacity-10 text-warning border border-warning border-opacity-10 rounded-pill px-3">Butuh
                                            Perbaikan ⚠️</span>
                                    <?php elseif ($doc['status_verifikasi'] == 'REJECTED'): ?>
                                        <span
                                            class="badge bg-danger bg-opacity-10 text-danger border border-danger border-opacity-10 rounded-pill px-3">Ditolak
                                            / Ganti Berkas ❌</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="alert alert-secondary py-2 px-3 rounded-3 small mb-3">
                                    <i class="bi bi-chat-dots-fill me-1"></i> Respon: <span class="fw-bold">"
                                        <?= $doc['catatan'] ?>"
                                    </span>
                                </div>
                            <?php endif; ?>

                            <div class="mb-2">
                                <label class="small fw-bold text-secondary mb-2">GANTI DENGAN FILE BARU (MAX 1MB,
                                    PDF):</label>
                                <input type="file" name="dokumen[<?= $doc['id'] ?>]"
                                    class="form-control rounded-pill file-validation" accept=".pdf">
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>

            <div class="glass-card mt-5 mb-5 border-0 shadow-lg text-center py-4"
                style="background: linear-gradient(135deg, #4361ee 0%, #3a0ca3 100%);">
                <p class="text-white opacity-75 mb-3 fw-bold">PASTIKAN SELURUH DOKUMEN YANG DIPERBAIKI SUDAH SESUAI
                    DENGAN PERMINTAAN VERIFIKATOR.</p>
                <button type="submit" class="btn btn-light rounded-pill px-5 py-3 fw-bold shadow">
                    <i class="bi bi-send-check-fill me-2 text-primary"></i> KIRIM PERBAIKAN SEKARANG
                </button>
            </div>
        </form>
    </div>
</div>

<script>
    document.addEventListener('change', function (e) {
        if (e.target.classList.contains('file-validation')) {
            const file = e.target.files[0];
            if (file && file.size > 1024 * 1024) {
                alert('Peringatan: Ukuran file "' + file.name + '" melebihi 1MB. Silakan kompres file Anda terlebih dahulu.');
                e.target.value = '';
            }
        }
    });
</script>
<?= $this->endSection() ?>