<section class="content-header">
    <h1><?= __('Accounts') ?></h1>

    <div class="actions">
        <?php if ($banned): ?>
            <a data-ajax class="btn btn-default btn-sm" href="<?= admin_url_to('/accounts') ?>"><?= __('All accounts') ?></a>
        <?php else: ?>
            <a data-ajax class="btn btn-default btn-sm" href="<?= admin_url_to('/accounts?banned=true') ?>"><?= __('Banned accounts') ?></a>
        <?php endif ?>
        <a data-load-with-modal data-modal="modal-search" class="btn btn-default btn-sm" href="<?= admin_url_to('/accounts/search') ?>"><?= __('Search') ?></a>
    </div>
</section>

<div class="modal" id="modal-search"></div>

<section class="content">
    <?php if (empty($accounts)): ?>
        <div class="callout callout-warning">
            <h4>Ops!</h4>
            <p><?= __('No account found') ?></p>
        </div>
    <?php else: ?>
        <div class="box box-default">
            <table class="table table-condensed table-hover table-striped">
                <thead>
                    <tr>
                        <th><?= __('Account') ?></th>
                        <th><?= __('Characters') ?></th>
                        <th><?= __('E-mail') ?></th>
                        <th><?= __('Last IP') ?></th>
                        <th width="10"></th>
                    </tr>
                </thead>

                <tbody>
                    <?php foreach ($accounts as $account): ?>
                        <tr<?= $account['blocked'] ? ' class="border-error"' : '' ?>>
                            <td>
                                <a data-ajax href="<?= admin_url_to('/accounts/edit/' . $account['username']) ?>"><?= $account['username'] ?></a>
                                <?php if ($account['blocked']): ?>
                                    <span class="label label-danger" style="vertical-align:1px;"><?= strtoupper(__('Blocked')) ?></span>
                                <?php endif ?>
                            </td>
                            <td style="width:350px">
                                <?php foreach ($account['characters'] as $key => $character): ?>
                                    <span class="label label-default">
                                        <a data-ajax href="<?= admin_url_to('/characters/edit/' . $character['name']) ?>"><?= $character['name'] ?></a>
                                    </span>
                                <?php endforeach ?>
                            </td>
                            <td><?= $account['email'] ?></td>
                            <td><?= $account['ip'] ?></td>
                            <td>
                                <a data-ajax href="<?= admin_url_to('/accounts/edit/' . $account['username']) ?>" class="btn btn-xs btn-default"><?= __('Edit') ?></a>
                            </td>
                        </tr>
                    <?php endforeach ?>
                </tbody>
            </table>

            <div class="paginator">
                <?= $paginator->toHtml() ?>
            </div>
        </div>
    <?php endif ?>
</section>