<?= $this->extend('layout/template') ?>

<?= $this->section('content') ?>
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h3 mb-1 text-gray-800 fw-bold">Input Kinerja</h1>
            <p class="mb-0 text-muted">Laporkan capaian kinerja sub kegiatan</p>
        </div>
        <a href="<?= base_url('opd_kinerja/dashboard') ?>" class="btn btn-secondary shadow-sm">
            <i class="fas fa-arrow-left me-1"></i> Kembali
        </a>
    </div>

    <div class="card shadow mb-4">
        <div class="card-body">
            <?php if(empty($subKegiatan)): ?>
                <div class="alert alert-warning">
                    <i class="fas fa-exclamation-triangle me-2"></i>
                    Belum ada data Sub Kegiatan yang ditugaskan ke OPD Anda. Silakan hubungi Admin Bidang atau Super Admin.
                </div>
            <?php else: ?>
                <form action="<?= base_url('opd_kinerja/store') ?>" method="post" enctype="multipart/form-data">
                    <h6 class="fw-bold text-primary mb-3">1. Informasi Kegiatan</h6>
                    <div class="mb-3">
                        <label for="sub_kegiatan_id" class="form-label fw-bold">Pilih Sub Kegiatan <span class="text-danger">*</span></label>
                        <select name="sub_kegiatan_id" id="sub_kegiatan_id" class="form-select" required>
                            <option value="">-- Pilih Sub Kegiatan --</option>
                            <?php foreach($subKegiatan as $sk): ?>
                                <?php 
                                    $programName = $sk['nama_program'];
                                    if (strlen($programName) > 50) {
                                        $programName = substr($programName, 0, 50) . '...';
                                    }
                                ?>
                                <option value="<?= $sk['id'] ?>" title="<?= $sk['nama_sub_kegiatan'] ?> (Program: <?= $sk['nama_program'] ?>)">
                                    <?= $sk['nama_sub_kegiatan'] ?> (Prog: <?= $programName ?>)
                                </option>
                            <?php endforeach; ?>
                        </select>
                    </div>

                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="triwulan" class="form-label fw-bold">Periode Laporan <span class="text-danger">*</span></label>
                                <select name="triwulan" id="triwulan" class="form-select" required>
                                    <option value="">-- Pilih Triwulan --</option>
                                    <option value="1">Triwulan 1 (Jan - Mar)</option>
                                    <option value="2">Triwulan 2 (Apr - Jun)</option>
                                    <option value="3">Triwulan 3 (Jul - Sep)</option>
                                    <option value="4">Triwulan 4 (Okt - Des)</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <h6 class="fw-bold text-primary mb-3 mt-4">2. Capaian Kinerja & Anggaran</h6>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="realisasi_kinerja" class="form-label fw-bold">Realisasi Kinerja Fisik <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" name="realisasi_kinerja" placeholder="Contoh: 80" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="satuan" class="form-label fw-bold">Satuan <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" name="satuan" placeholder="Contoh: Dokumen / %" required>
                            </div>
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="kinerja" class="form-label fw-bold">Deskripsi Capaian</label>
                        <textarea name="kinerja" rows="3" class="form-control" placeholder="Jelaskan detail capaian kinerja..."></textarea>
                    </div>

                    <div class="mb-3">
                        <label for="realisasi_anggaran" class="form-label fw-bold">Realisasi Anggaran (Rp) <span class="text-danger">*</span></label>
                        <input type="number" class="form-control" name="realisasi_anggaran" placeholder="0" required>
                    </div>

                    <h6 class="fw-bold text-primary mb-3 mt-4">3. Analisis & Bukti</h6>
                    <div class="row">
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="faktor_pendukung" class="form-label fw-bold">Faktor Pendukung</label>
                                <textarea name="faktor_pendukung" rows="3" class="form-control"></textarea>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="mb-3">
                                <label for="faktor_penghambat" class="form-label fw-bold">Faktor Penghambat</label>
                                <textarea name="faktor_penghambat" rows="3" class="form-control"></textarea>
                            </div>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label for="file_bukti" class="form-label fw-bold">Upload Bukti Dukung (PDF/JPG/PNG) <span class="text-danger">*</span></label>
                        <input type="file" class="form-control" name="file_bukti" accept=".pdf,.jpg,.jpeg,.png" required>
                        <div class="form-text">Maksimal 2MB.</div>
                    </div>

                    <hr>
                    <div class="d-flex justify-content-end">
                        <button type="submit" class="btn btn-primary px-4"><i class="fas fa-paper-plane me-1"></i> Kirim Laporan</button>
                    </div>
                </form>
            <?php endif; ?>
        </div>
    </div>
</div>
<?= $this->endSection() ?>
