<?= $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">Daftar Bidang</h1>
            <p class="mb-0 text-muted">Master data bidang Bappeda</p>
        </div>
        <a href="<?= base_url('bidang/create') ?>" class="btn btn-primary shadow-sm">
            <i class="fas fa-plus fa-sm text-white-50 me-1"></i> Tambah Bidang
        </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-header bg-white py-3 border-0 d-flex align-items-center justify-content-between">
            <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-layer-group me-2"></i>Data Bidang</h6>
        </div>
        <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="8%" class="text-center py-3">No</th>
                            <th class="py-3">Nama Bidang</th>
                            <th width="20%" class="text-center py-3">Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach($bidang as $index => $b): ?>
                        <tr>
                            <td class="text-center fw-bold text-secondary"><?= $index + 1 ?></td>
                            <td>
                                <div class="d-flex align-items-center">
                                    <div class="bg-info bg-opacity-10 text-info rounded p-2 me-3">
                                        <i class="fas fa-folder"></i>
                                    </div>
                                    <span class="fw-bold"><?= $b['nama_bidang'] ?></span>
                                </div>
                            </td>
                            <td class="text-center">
                                <a href="<?= base_url('bidang/edit/'.$b['id']) ?>" class="btn btn-warning btn-sm btn-icon-split shadow-sm me-1" title="Edit">
                                    <span class="icon text-white-50"><i class="fas fa-edit"></i></span>
                                </a>
                                <a href="<?= base_url('bidang/delete/'.$b['id']) ?>" class="btn btn-danger btn-sm btn-icon-split shadow-sm" onclick="return confirm('Yakin ingin menghapus bidang ini?')" title="Hapus">
                                    <span class="icon text-white-50"><i class="fas fa-trash"></i></span>
                                </a>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="card-footer bg-white border-0 py-3">
            <small class="text-muted">Total <?= count($bidang) ?> Bidang terdaftar</small>
        </div>
    </div>
</div>
<?= $this->endSection() ?>
