<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-3">
        <h4 class="mb-0 text-primary">Satuan Unit</h4>
    </div>

    <div class="card shadow-sm rounded mb-4">
        <div class="card-body">
            <form action="<?= base_url('admin/unit/save') ?>" method="post" class="row gy-2 gx-3 align-items-center">
                <div class="col-sm-9">
                    <input type="text" name="nama" class="form-control form-control-sm" placeholder="Nama Unit" required>
                </div>
                <div class="col-sm-3">
                    <button class="btn btn-sm btn-success w-100">
                        <i class="fas fa-plus-circle me-1"></i> Tambah
                    </button>
                </div>
            </form>
        </div>
    </div>

    <div class="card shadow-sm rounded">
        <div class="card-body table-responsive">
            <table class="table table-bordered table-hover table-sm align-middle">
                <thead class="table-light">
                    <tr class="text-center">
                        <th width="50">#</th>
                        <th>Nama Unit</th>
                        <th width="150">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach($units as $key => $u): ?>
                    <tr>
                        <td class="text-center"><?= $key+1 ?></td>
                        <td><?= esc($u['nama']) ?></td>
                        <td class="text-center">
                            <a href="<?= base_url('admin/unit/edit/' . $u['id']) ?>" class="btn btn-warning btn-sm">
                                <i class="fas fa-edit"></i> Edit
                            </a>
                            <a href="<?= base_url('admin/unit/delete/' . $u['id']) ?>" class="btn btn-danger btn-sm" onclick="return confirm('Hapus data?')">
                                <i class="fas fa-trash-alt"></i> Hapus
                            </a>
                        </td>
                    </tr>
                    <?php endforeach ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

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