<?= $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">Kelola Jadwal Pengisian</h1>
            <p class="mb-0 text-muted">Atur jadwal pengisian laporan kinerja triwulan</p>
        </div>
        <a href="<?= base_url('jadwal/create') ?>" class="btn btn-primary shadow-sm">
            <i class="fas fa-plus fa-sm text-white-50 me-1"></i> Tambah Jadwal
        </a>
    </div>

    <?php if(session()->getFlashdata('success')): ?>
        <div class="alert alert-success alert-dismissible fade show shadow-sm border-0 border-start border-success border-4" role="alert">
            <i class="fas fa-check-circle me-2"></i> <?= session()->getFlashdata('success') ?>
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    <?php endif; ?>

    <div class="card shadow-sm border-0 mb-4 rounded-3">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover table-striped align-middle mb-0" width="100%" cellspacing="0">
                    <thead class="bg-light text-secondary">
                        <tr>
                            <th width="5%" class="text-center py-3">No</th>
                            <th>Tahun</th>
                            <th>Triwulan</th>
                            <th>Periode</th>
                            <th>Status</th>
                            <th>Keterangan</th>
                            <th class="text-center">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if(empty($jadwal)): ?>
                            <tr>
                                <td colspan="7" class="text-center py-5 text-muted">Belum ada jadwal yang dibuat.</td>
                            </tr>
                        <?php else: ?>
                            <?php foreach($jadwal as $index => $j): ?>
                            <tr>
                                <td class="text-center fw-bold text-secondary"><?= $index + 1 ?></td>
                                <td><?= $j['tahun'] ?></td>
                                <td>Triwulan <?= $j['triwulan'] ?></td>
                                <td><?= date('d M Y', strtotime($j['tanggal_mulai'])) ?> - <?= date('d M Y', strtotime($j['tanggal_selesai'])) ?></td>
                                <td>
                                    <?php if($j['status'] == 'Aktif'): ?>
                                        <span class="badge bg-success">Aktif</span>
                                    <?php else: ?>
                                        <span class="badge bg-secondary">Tutup</span>
                                    <?php endif; ?>
                                </td>
                                <td><?= $j['keterangan'] ?></td>
                                <td class="text-center">
                                    <a href="<?= base_url('jadwal/delete/'.$j['id']) ?>" class="btn btn-danger btn-sm btn-icon-split shadow-sm" onclick="return confirm('Yakin ingin menghapus jadwal ini?')" title="Hapus">
                                        <span class="icon text-white-50"><i class="fas fa-trash"></i></span>
                                    </a>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?= $this->endSection() ?>
