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

<?= $this->section('content') ?>
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h3 mb-0 text-gray-800 fw-bold">Progres Evaluasi</h1>
        <form action="" method="get" class="d-flex gap-2">
            <select name="tahun" class="form-select form-select-sm">
                <?php for($i = date('Y'); $i >= date('Y')-2; $i--): ?>
                    <option value="<?= $i ?>" <?= $tahun == $i ? 'selected' : '' ?>><?= $i ?></option>
                <?php endfor; ?>
            </select>
            <select name="triwulan" class="form-select form-select-sm">
                <option value="1" <?= $triwulan == '1' ? 'selected' : '' ?>>Triwulan 1</option>
                <option value="2" <?= $triwulan == '2' ? 'selected' : '' ?>>Triwulan 2</option>
                <option value="3" <?= $triwulan == '3' ? 'selected' : '' ?>>Triwulan 3</option>
                <option value="4" <?= $triwulan == '4' ? 'selected' : '' ?>>Triwulan 4</option>
            </select>
            <button type="submit" class="btn btn-sm btn-primary">Filter</button>
        </form>
    </div>

    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">Status Pelaporan OPD (Tahun <?= $tahun ?> - Triwulan <?= $triwulan ?>)</h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered table-hover" width="100%" cellspacing="0">
                    <thead class="bg-light text-center align-middle">
                        <tr>
                            <th width="5%">No</th>
                            <th>Nama OPD</th>
                            <th width="15%">Total Kegiatan</th>
                            <th width="15%">Laporan Masuk</th>
                            <th width="15%">Disetujui</th>
                            <th width="20%">Persentase</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $no = 1; foreach($opd_data as $o): ?>
                        <tr>
                            <td class="text-center"><?= $no++ ?></td>
                            <td class="fw-bold"><?= $o['nama_opd'] ?></td>
                            <td class="text-center"><?= $o['total_kegiatan'] ?></td>
                            <td class="text-center"><?= $o['laporan_masuk'] ?></td>
                            <td class="text-center text-success fw-bold"><?= $o['status_selesai'] ?></td>
                            <td>
                                <div class="d-flex align-items-center">
                                    <div class="progress flex-grow-1 me-2" style="height: 20px;">
                                        <div class="progress-bar <?= $o['persentase'] == 100 ? 'bg-success' : ($o['persentase'] > 50 ? 'bg-info' : 'bg-warning') ?>" 
                                             role="progressbar" 
                                             style="width: <?= $o['persentase'] ?>%" 
                                             aria-valuenow="<?= $o['persentase'] ?>" 
                                             aria-valuemin="0" 
                                             aria-valuemax="100">
                                        </div>
                                    </div>
                                    <span class="small fw-bold"><?= $o['persentase'] ?>%</span>
                                </div>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?= $this->endSection() ?>
