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

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

<div class="row mb-4 align-items-center">
    <div class="col-md-6">
        <h4 class="fw-bold text-success"><i class="fa-solid fa-user-shield me-2"></i> Manajemen Akun Sistem</h4>
        <p class="text-muted mb-0">Kelola hak akses login untuk seluruh staf KPH III.</p>
    </div>
    <div class="col-md-6 text-md-end mt-3 mt-md-0">
        <a href="<?= base_url('akun/tambah') ?>" class="btn btn-success rounded-pill shadow-sm"><i class="fa-solid fa-plus me-2"></i> Tambah Akun Baru</a>
    </div>
</div>

<div class="card shadow-sm border-0">
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="table-light text-muted">
                    <tr>
                        <th class="ps-4">No</th>
                        <th>Nama Lengkap</th>
                        <th>Username Login</th>
                        <th>Level Akses (Role)</th>
                        <th class="text-center pe-4">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $no = 1; foreach($akun as $row) : ?>
                    <tr>
                        <td class="ps-4"><?= $no++ ?></td>
                        <td class="fw-bold text-dark"><?= $row['nama_lengkap'] ?></td>
                        <td><span class="badge bg-light text-dark border"><?= $row['username'] ?></span></td>
                        <td>
                            <?php if($row['role'] == 'Admin' || $row['role'] == 'Kepala KPH'): ?>
                                <span class="badge bg-danger rounded-pill px-3"><?= $row['role'] ?></span>
                            <?php else: ?>
                                <span class="badge bg-primary rounded-pill px-3"><?= $row['role'] ?></span>
                            <?php endif; ?>
                        </td>
                        <td class="text-center pe-4">
                            <!-- Tombol Edit & Hapus -->
                            <a href="<?= base_url('akun/edit/' . $row['id_user']) ?>" class="btn btn-sm btn-warning rounded-circle shadow-sm" title="Edit Data"><i class="fa-solid fa-pen text-dark"></i></a>
                            
                            <?php if($row['id_user'] != session()->get('id_user')): // Sembunyikan hapus untuk diri sendiri ?>
                            <a href="<?= base_url('akun/hapus/' . $row['id_user']) ?>" class="btn btn-sm btn-outline-danger rounded-circle shadow-sm ms-1" onclick="return confirm('Yakin ingin menghapus akun ini?')" title="Hapus Data"><i class="fa-solid fa-trash"></i></a>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

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