<form method="post" action="<?= site_url('security/role/save') ?>">

<input type="hidden" name="id" value="<?= $role['id'] ?? '' ?>">

<div class="mb-3">
    <label class="fw-bold">Nama Role</label>
    <input type="text"
           name="name"
           class="form-control"
           value="<?= $role['name'] ?? '' ?>"
           required>
</div>

<hr>

<h6 class="text-muted">Hak Akses</h6>

<?php foreach ($permissions as $group => $items): ?>
<div class="border rounded p-3 mb-3">
    <b class="text-primary text-uppercase"><?= esc($group) ?></b>

    <div class="row mt-2">
        <?php foreach ($items as $p): ?>
        <div class="col-md-4">
            <label class="d-flex align-items-center gap-2">
                <input type="checkbox"
                       name="permissions[]"
                       value="<?= $p['id'] ?>"
                       <?= in_array($p['id'], $rolePermissions ?? []) ? 'checked' : '' ?>>
                <?= esc($p['name']) ?>
            </label>
        </div>
        <?php endforeach ?>
    </div>
</div>
<?php endforeach ?>

<button class="btn btn-success">
    <i class="fas fa-save"></i> Simpan Role
</button>

</form>
