<?= $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">Detail Laporan</h1>
            <p class="mb-0 text-muted">Periksa detail capaian kinerja OPD</p>
        </div>
        <a href="<?= base_url('admin_bidang/verifikasi') ?>" class="btn btn-secondary btn-sm shadow-sm">
            <i class="fas fa-arrow-left me-1"></i> Kembali
        </a>
    </div>

    <div class="row">
        <!-- Informasi Kegiatan -->
        <div class="col-lg-12 mb-4">
            <div class="card shadow border-left-primary">
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6">
                            <table class="table table-borderless table-sm">
                                <tr>
                                    <td width="150" class="fw-bold">OPD</td>
                                    <td>: <?= $laporan['nama_opd'] ?></td>
                                </tr>
                                <tr>
                                    <td class="fw-bold">Program</td>
                                    <td>: <?= $laporan['nama_program'] ?></td>
                                </tr>
                                <tr>
                                    <td class="fw-bold">Kegiatan</td>
                                    <td>: <?= $laporan['nama_kegiatan'] ?></td>
                                </tr>
                                <tr>
                                    <td class="fw-bold">Sub Kegiatan</td>
                                    <td>: <?= $laporan['nama_sub_kegiatan'] ?></td>
                                </tr>
                            </table>
                        </div>
                        <div class="col-md-6">
                            <table class="table table-borderless table-sm">
                                <tr>
                                    <td width="150" class="fw-bold">Tahun / Triwulan</td>
                                    <td>: <?= $laporan['tahun'] ?> / TW <?= $laporan['triwulan'] ?></td>
                                </tr>
                                <tr>
                                    <td class="fw-bold">Status Saat Ini</td>
                                    <td>: <span class="badge bg-warning text-dark"><?= $laporan['status'] ?></span></td>
                                </tr>
                                <tr>
                                    <td class="fw-bold">Tanggal Kirim</td>
                                    <td>: <?= date('d F Y H:i', strtotime($laporan['created_at'])) ?></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Detail Capaian -->
        <div class="col-lg-8">
            <div class="card shadow mb-4">
                <div class="card-header py-3">
                    <h6 class="m-0 font-weight-bold text-primary">Capaian Kinerja & Anggaran</h6>
                </div>
                <div class="card-body">
                    <h6 class="fw-bold text-secondary mb-3 border-bottom pb-2">Kinerja Fisik</h6>
                    <div class="row mb-4">
                        <div class="col-md-6">
                            <label class="small text-muted">Target Kinerja</label>
                            <p class="fw-bold"><?= $laporan['target_kinerja'] ?> <?= $laporan['satuan'] ?></p>
                        </div>
                        <div class="col-md-6">
                            <label class="small text-muted">Realisasi Kinerja</label>
                            <p class="fw-bold text-success"><?= $laporan['realisasi_kinerja'] ?> <?= $laporan['satuan'] ?></p>
                        </div>
                        <div class="col-12 mt-2">
                            <label class="small text-muted">Deskripsi Capaian</label>
                            <p class="bg-light p-3 rounded"><?= $laporan['kinerja'] ?: '-' ?></p>
                        </div>
                    </div>

                    <h6 class="fw-bold text-secondary mb-3 border-bottom pb-2">Realisasi Anggaran</h6>
                    <div class="row mb-4">
                        <div class="col-md-6">
                            <label class="small text-muted">Pagu Anggaran</label>
                            <p class="fw-bold">Rp <?= number_format($laporan['target_anggaran'], 0, ',', '.') ?></p>
                        </div>
                        <div class="col-md-6">
                            <label class="small text-muted">Realisasi Anggaran</label>
                            <p class="fw-bold text-success">Rp <?= number_format($laporan['realisasi_anggaran'], 0, ',', '.') ?></p>
                        </div>
                        <div class="col-12">
                            <div class="progress mt-2" style="height: 20px;">
                                <?php 
                                    $persen = ($laporan['target_anggaran'] > 0) ? ($laporan['realisasi_anggaran'] / $laporan['target_anggaran']) * 100 : 0;
                                    $bg = 'bg-success';
                                    if($persen > 100) $bg = 'bg-danger';
                                    elseif($persen < 50) $bg = 'bg-warning';
                                ?>
                                <div class="progress-bar <?= $bg ?>" role="progressbar" style="width: <?= min($persen, 100) ?>%;" aria-valuenow="<?= $persen ?>" aria-valuemin="0" aria-valuemax="100"><?= number_format($persen, 1) ?>%</div>
                            </div>
                        </div>
                    </div>

                    <h6 class="fw-bold text-secondary mb-3 border-bottom pb-2">Faktor Pendukung & Penghambat</h6>
                    <div class="row">
                        <div class="col-md-6">
                            <label class="small text-muted">Faktor Pendukung</label>
                            <p class="bg-light p-2 rounded small"><?= $laporan['faktor_pendukung'] ?: '-' ?></p>
                        </div>
                        <div class="col-md-6">
                            <label class="small text-muted">Faktor Penghambat</label>
                            <p class="bg-light p-2 rounded small"><?= $laporan['faktor_penghambat'] ?: '-' ?></p>
                        </div>
                    </div>
                    
                    <?php if($laporan['file_bukti']): ?>
                    <div class="mt-3">
                        <h6 class="fw-bold text-secondary mb-2">Bukti Dukung</h6>
                        <a href="<?= base_url('uploads/'.$laporan['file_bukti']) ?>" target="_blank" class="btn btn-outline-primary btn-sm">
                            <i class="fas fa-paperclip"></i> Lihat Dokumen
                        </a>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <!-- Form Verifikasi -->
        <div class="col-lg-4">
            <div class="card shadow mb-4">
                <div class="card-header py-3 bg-primary text-white">
                    <h6 class="m-0 font-weight-bold"><i class="fas fa-check-double me-2"></i>Verifikasi</h6>
                </div>
                <div class="card-body">
                    <form action="<?= base_url('admin_bidang/update_status') ?>" method="post">
                        <input type="hidden" name="id" value="<?= $laporan['id'] ?>">
                        
                        <div class="mb-3">
                            <label for="status" class="form-label fw-bold">Keputusan</label>
                            <select name="status" id="status" class="form-select" required>
                                <option value="">Pilih Keputusan...</option>
                                <option value="Disetujui" <?= $laporan['status'] == 'Disetujui' ? 'selected' : '' ?>>Setujui Laporan</option>
                                <option value="Revisi" <?= $laporan['status'] == 'Revisi' ? 'selected' : '' ?>>Minta Revisi</option>
                                <option value="Ditolak" <?= $laporan['status'] == 'Ditolak' ? 'selected' : '' ?>>Tolak Laporan</option>
                            </select>
                        </div>

                        <div class="mb-3">
                            <label for="catatan" class="form-label fw-bold">Catatan / Feedback</label>
                            <textarea name="catatan" id="catatan" rows="5" class="form-control" placeholder="Berikan catatan untuk OPD..."><?= $laporan['catatan'] ?></textarea>
                            <div class="form-text text-muted small">Catatan ini akan muncul di dashboard OPD.</div>
                        </div>

                        <div class="d-grid">
                            <button type="submit" class="btn btn-primary">Simpan Keputusan</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<?= $this->endSection() ?>
