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

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

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

<section class="content">
    <?php if (empty($characters)): ?>
        <div class="callout callout-warning">
            <h4>Ops!</h4>
            <p><?= __('No character found') ?></p>
        </div>
    <?php else: ?>
        <div class="box box-default">
            <table class="table table-condensed table-hover table-striped">
                <thead>
                    <tr>
                        <th><?= __('Name') ?></th>
                        <th><?= __('Class') ?></th>
                        <th><?= __('Account') ?></th>
                        <th><?= __('Guild') ?></th>
                        <th><?= __('Status') ?></th>
                        <th><?= __('Map') ?></th>
                        <th width="10"></th>
                    </tr>
                </thead>

                <tbody>
                    <?php foreach ($characters as $character): ?>
                        <tr<?= $character['code'] == 1 ? ' class="border-error"' : '' ?>>
                            <td>
                                <a data-ajax href="<?= admin_url_to('/characters/edit/' . $character['name']) ?>"><?= $character['name'] ?></a>
                            </td>
                            <td><?= util('Character')->className($character['class']) ?></td>
                            <td>
                                <a data-ajax href="<?= admin_url_to('/accounts/edit/' . $character['account']) ?>"><?= $character['account'] ?></a>
                            </td>
                            <td><?= $character['guild'] ?></td>
                            <td><?= util('Character')->status($character['status']) ?></td>
                            <td>
                                <?= util('Character')->mapName($character['map']) ?> (<?= $character['positionX'] ?>x<?= $character['positionY'] ?>)
                            </td>
                            <td>
                                <a data-ajax href="<?= admin_url_to('/characters/edit/' . $character['name']) ?>" class="btn btn-xs btn-default"><?= __('Edit') ?></a>
                            </td>
                        </tr>
                    <?php endforeach ?>
                </tbody>
            </table>

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