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

<?= $this->section('content') ?>

<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
    <h1 class="page-title" style="margin-bottom: 0;">Data Master Fakultas</h1>
    <a href="<?= base_url('fakultas/create') ?>" class="btn btn-primary">
        <i class='bx bx-plus'></i> Tambah Fakultas
    </a>
</div>

<?php if(session()->getFlashdata('success')) : ?>
    <div class="alert alert-success">
        <?= session()->getFlashdata('success') ?>
    </div>
<?php endif; ?>

<div class="table-container">
    <table class="table">
        <thead>
            <tr>
                <th width="5%">No</th>
                <th width="15%">Kode Fakultas</th>
                <th>Nama Fakultas</th>
                <th width="15%" style="text-align: center;">Aksi</th>
            </tr>
        </thead>
        <tbody>
            <?php if(empty($fakultas)) : ?>
                <tr>
                    <td colspan="4" style="text-align: center; color: var(--text-muted);">Belum ada data fakultas.</td>
                </tr>
            <?php else : ?>
                <?php $i = 1; foreach($fakultas as $f) : ?>
                    <tr>
                        <td><?= $i++ ?></td>
                        <td><strong><?= esc($f['kode_fakultas']) ?></strong></td>
                        <td><?= esc($f['nama_fakultas']) ?></td>
                        <td style="text-align: center;">
                            <a href="<?= base_url('fakultas/edit/'.$f['id']) ?>" class="btn btn-sm btn-warning" title="Edit">
                                <i class='bx bx-edit-alt'></i>
                            </a>
                            <form action="<?= base_url('fakultas/delete/'.$f['id']) ?>" method="post" style="display: inline;" onsubmit="return confirm('Apakah Anda yakin ingin menghapus data ini?');">
                                <?= csrf_field() ?>
                                <button type="submit" class="btn btn-sm btn-danger" title="Hapus">
                                    <i class='bx bx-trash'></i>
                                </button>
                            </form>
                        </td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </tbody>
    </table>
</div>

<?= $this->endSection() ?>
