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

<div class="card">
    <div class="card-header ch-alt">
        <h2><?=__('User Accounts') ?></h2>

        <a class="btn bgm-blue btn-float" role="button" title="<?=__('Add %s', __('User')) ?>" href="<?=$router->named('admin:users:add') ?>">
            <span class="sr-only"><?=__('Add %s', __('User')) ?></span>
            <i class="zmdi zmdi-plus"></i>
        </a>
    </div>
    <div class="table-responsive">
        <table class="table table-striped">
            <colgroup>
                <col width="30%">
                <col width="40%">
                <col width="30%">
            </colgroup>
            <thead>
            <tr>
                <th><?=__('Actions') ?></th>
                <th><?=__('E-mail Address') ?></th>
                <th><?=__('Roles') ?></th>
            </tr>
            </thead>
            <tbody>
            <?php foreach($users as $user_row): ?>
                <tr class="input">
                    <td>
                    <?php if ($user_row->getId() !== $user->getId()): ?>
                        <a class="btn btn-sm btn-primary" href="<?=$router->named('admin:users:impersonate', ['id' => $user_row->getId(), 'csrf' => $csrf]) ?>"><?=__('Log In') ?></a>
                    <?php endif; ?>
                        <a class="btn btn-sm btn-default" href="<?=$router->named('admin:users:edit', ['id' => $user_row->getId()]) ?>"><?=__('Edit') ?></a>
                        <a class="btn btn-sm btn-danger" href="<?=$router->named('admin:users:delete', ['id' => $user_row->getId(), 'csrf' => $csrf]) ?>"><?=__('Delete') ?></a>
                    </td>
                    <td><?=$this->mailto($user_row->getEmail()) ?> <?php if ($user_row->getId() === $user->getId()): ?><?=__('(You)') ?><?php endif; ?></td>
                    <td>
                        <small>
                            <?php
                            if (count($user_row->getRoles()) > 0)
                            {
                                foreach($user_row->getRoles() as $role)
                                    echo '<div>'.$this->e($role->getName()).'</div>';
                            }
                            ?>
                        </small>
                    </td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
