<?php $this->layout('main', ['title' => __('Permissions'), 'manual' => true]); ?>

<div class="card">
    <div class="card-header ch-alt">
        <h2><?=__('Permissions') ?></h2>
        <a class="btn bgm-blue btn-float" role="button" title="<?=__('Add %s', __('Permission')) ?>" href="<?=$router->named('admin:permissions:add') ?>">
            <span class="sr-only"><?=__('Add %s', __('Permission')) ?></span>
            <i class="zmdi zmdi-plus"></i>
        </a>
    </div>
    <div class="table-responsive">
        <table class="table table-striped">
            <colgroup>
                <col width="20%">
                <col width="20%">
                <col width="30%">
                <col width="30%">
            </colgroup>
            <thead>
            <tr>
                <th><?=__('Actions') ?></th>
                <th><?=__('Role Name') ?></th>
                <th><?=__('System-Wide Permissions') ?></th>
                <th><?=__('Per-Station Permissions') ?></th>
            </tr>
            </thead>
            <tbody>
            <?php foreach($roles as $role): ?>
                <tr class="input">
                    <td class="center">
                        <a class="btn btn-sm btn-primary" href="<?=$router->named('admin:permissions:edit', ['id' => $role['id']]) ?>"><?=__('Edit') ?></a>

                        <?php if( $role['id'] != 1 ): ?>
                            <a class="btn btn-sm btn-danger" href="<?=$router->named('admin:permissions:delete', ['id' => $role['id'], 'csrf' => $csrf]) ?>"><?=__('Delete') ?></a>
                        <?php else: ?>
                            <a class="btn btn-sm btn-danger disabled" href="#" onclick="alert('<?=__('This role cannot be deleted.') ?>'); return false;"><?=__('Delete') ?></a>
                        <?php endif; ?>
                    </td>
                    <td>
                        <big><?=$this->e($role['name']) ?></big>
                    </td>
                    <td>
                        <?=implode($role['permissions_global'], ', ') ?>
                    </td>
                    <td>
                    <?php foreach($role['permissions_station'] as $station_name => $station_perms): ?>
                        <div><b><?=$this->e($station_name) ?></b>: <?=implode($station_perms, ', ') ?></div>
                    <?php endforeach; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
