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

<div class="card">
    <div class="card-header bg-primary-dark">
        <h2 class="card-title"><?=__('User Accounts') ?></h2>
    </div>
    <div class="card-actions">
        <a class="btn btn-outline-primary" role="button" href="<?=$router->named('admin:users:add') ?>">
            <i class="material-icons" aria-hidden="true">add</i>
            <?=__('Add User') ?>
        </a>
    </div>
    <table class="table table-responsive-md table-striped mb-0">
        <colgroup>
            <col width="30%">
            <col width="35%">
            <col width="35%">
        </colgroup>
        <thead>
        <tr>
            <th><?=__('Actions') ?></th>
            <th><?=__('E-mail Address') ?></th>
            <th><?=__('Roles') ?></th>
        </tr>
        </thead>
        <tbody>
        <?php foreach($users as $user_row): ?>
            <?php /** @var \App\Entity\User $user_row */ ?>
            <tr class="align-middle">
                <td>
                    <div class="btn-group btn-group-sm">
                    <?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-dark" href="<?=$router->named('admin:users:edit', ['id' => $user_row->getId()]) ?>"><?=__('Edit') ?></a>
                    <?php if ($user_row->getId() !== $user->getId()): ?>
                        <a class="btn btn-sm btn-danger" data-confirm-title="<?=$this->e(__('Delete user "%s"?', $user_row->getEmail())) ?>" href="<?=$router->named('admin:users:delete', ['id' => $user_row->getId(), 'csrf' => $csrf]) ?>"><?=__('Delete') ?></a>
                    <?php else: ?>
                        <a class="btn btn-sm btn-danger disabled" href=""><?=__('Delete') ?></a>
                    <?php endif; ?>
                    </div>
                </td>
                <td>
                    <div class="text-lg-left"><?=$this->e($user_row->getName()) ?></div>
                    <div>
                        <?=$this->mailto($user_row->getEmail()) ?>
                        <?php if ($user_row->getId() === $user->getId()): ?><?=__('(You)') ?><?php endif; ?>
                    </div>
                </td>
                <td>
                    <?php foreach($user_row->getRoles() as $role): ?>
                        <div><?=$this->e($role->getName()) ?></div>
                    <?php endforeach; ?>
                </td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>
