<?= $this->extend('layout/admin') ?>
<?= $this->section('content') ?>

<div class="card shadow-sm">
    <div class="card-header bg-dark text-white d-flex justify-content-between">
        <b><i class="fas fa-user-shield"></i> Role & Permission</b>
        <button class="btn btn-success btn-sm" onclick="openRole()">
            <i class="fas fa-plus"></i> Role Baru
        </button>
    </div>

    <div class="card-body">
        <table class="table table-bordered table-hover">
            <thead class="table-secondary">
                <tr>
                    <th width="5%">No</th>
                    <th>Role</th>
                    <th>Deskripsi</th>
                    <th>Permission</th>
                    <th width="15%">Aksi</th>
                </tr>
            </thead>
            <tbody>
                <?php $no=1; foreach($roles as $r): ?>
                <tr>
                    <td><?= $no++ ?></td>
                    <td>
                        <b><?= esc($r['name']) ?></b>
                        <?php if ($r['is_system']): ?>
                            <span class="badge bg-danger ms-1">SYSTEM</span>
                        <?php endif ?>
                    </td>
                    <td><?= esc($r['description']) ?></td>
                    <td>
                        <?php foreach ($r['permissions'] as $p): ?>
                            <span class="badge bg-primary mb-1"><?= $p ?></span>
                        <?php endforeach ?>
                    </td>
                    <td>
                        <button class="btn btn-warning btn-sm">
                            <i class="fas fa-edit"></i>
                        </button>
                        <?php if (!$r['is_system']): ?>
                        <button class="btn btn-danger btn-sm">
                            <i class="fas fa-trash"></i>
                        </button>
                        <?php endif ?>
                    </td>
                </tr>
                <?php endforeach ?>
            </tbody>
        </table>
    </div>
</div>

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