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

<div class="card">

<div class="card-header bg-primary text-white">
    <b>ROLE ACCESS CONTROL</b>
    <span class="float-end">Role: <?= $role->role_name ?></span>
</div>

<div class="card-body">

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

<input type="hidden" name="role_id" value="<?= $role->id ?>">

<table class="table table-bordered table-hover">
<thead class="table-dark text-center">
<tr>
    <th>Menu</th>
    <th>View</th>
    <th>Create</th>
    <th>Update</th>
    <th>Delete</th>
</tr>
</thead>

<tbody>

<?php foreach($menus as $m): 
    $perm = $access[$m->id] ?? null;
?>
<tr>
    <td style="padding-left:<?= $m->parent_id ? '40px':'10px' ?>">
        <?= $m->title ?>
    </td>

    <?php foreach(['view','create','update','delete'] as $p): ?>
    <td class="text-center">
        <input type="checkbox" 
            name="menus[<?= $m->id ?>][<?= $p ?>]"
            <?= $perm && $perm->{'can_'.$p} ? 'checked':'' ?>
        >
    </td>
    <?php endforeach ?>

</tr>
<?php endforeach ?>

</tbody>

</table>

<div class="text-end mt-3">
    <button class="btn btn-success">Save Changes</button>
</div>

</form>

</div>
</div>

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