<div class="main-content">
  <div class="container-fluid" style="margin-top: 50px;">
    <div class="row">
      <div class="col-12">
        <h2><i class="bi bi-shield-lock me-2"></i>Manajemen Admin OPD</h2>
        <a href="<?= base_url('admin_group/create') ?>" class="btn btn-success mb-3">+ Tambah Admin OPD</a>

        <?php if ($this->session->flashdata('success')): ?>
          <div class="alert alert-success"><?= $this->session->flashdata('success') ?></div>
        <?php endif; ?>
        <?php if ($this->session->flashdata('error')): ?>
          <div class="alert alert-danger"><?= $this->session->flashdata('error') ?></div>
        <?php endif; ?>

        <div class="card">
          <div class="card-body">
            <table class="table table-bordered table-hover">
              <thead>
                <tr>
                  <th>No</th>
                  <th>Username</th>
                  <th>Nama Lengkap</th>
                  <th>OPD</th>
                  <th>Role</th>
                  <th>Aksi</th>
                </tr>
              </thead>
              <tbody>
                <?php $no = 1; foreach ($admins as $a): ?>
                  <?php if ($a->role === 'superadmin') continue; // Sembunyikan superadmin ?>
                  <tr>
                    <td><?= $no++ ?></td>
                    <td><?= htmlspecialchars($a->username) ?></td>
                    <td><?= htmlspecialchars($a->nama_lengkap) ?></td>
                    <td><?= htmlspecialchars($a->skpd) ?></td>
                    <td><?= ucfirst($a->role) ?></td>
                    <td>
                      <a href="<?= base_url("admin_group/edit/{$a->id}") ?>" class="btn btn-sm btn-warning">Edit</a>
                      <a href="<?= base_url("admin_group/delete/{$a->id}") ?>" class="btn btn-sm btn-danger" onclick="return confirm('Yakin hapus?')">Hapus</a>
                    </td>
                  </tr>
                <?php endforeach; ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
