<?php

/**
 * @var Mobicms\Render\Template\Template $this
 * @var array<int, array<string, mixed>> $items
 * @var int $total
 * @var int $per_page
 * @var bool $no_buttons
 * @var string|null $message
 * @var string $add_url
 * @var string $search_url
 * @var string $clear_url
 * @var string $pagination
 * @var string $csrf_token
 */

$this->layout('system::layout/default');
?>

<?php if (! empty($message)): ?>
    <?= $this->fetch('system::app/alert', ['alert_type' => 'alert-info', 'alert' => $message]) ?>
<?php endif; ?>
<table class="table table-striped">
    <thead>
    <tr class="bg-secondary text-white">
        <th><?= __('IP address') ?></th>
        <th><?= __('Reason') ?></th>
    </tr>
    </thead>
    <tbody>
    <?php if (empty($items)): ?>
        <tr>
            <td colspan="2" class="text-center"><?= __('The list is empty') ?></td>
        </tr>
    <?php endif; ?>
    <?php foreach ($items as $item): ?>
        <tr>
            <td><a href="<?= $this->e($item['detail_url']) ?>"><?= $this->e($item['ips']) ?></a></td>
            <td><?= $this->e($item['reason_label']) ?></td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>

<div class="mt-2">
    <?php if ($total > $per_page): ?>
        <div><?= $pagination ?></div>
    <?php endif; ?>
    <?php if ($total > 0): ?>
        <div><?= __('Total:') ?> <?= $total ?></div>
    <?php endif; ?>
</div>
<?php if (empty($no_buttons)): ?>
    <div class="mt-2 mb-3 d-flex">
        <form action="<?= $this->e($add_url) ?>" method="post" class="me-2">
            <input type="hidden" name="csrf_token" value="<?= $csrf_token ?>">
            <input class="btn btn-danger" type="submit" value="<?= __('Add') ?>">
        </form>
        <?php if ($total > 0): ?>
            <a href="<?= $this->e($search_url) ?>" class="btn btn-primary me-2"><?= __('Search') ?></a>
            <a href="<?= $this->e($clear_url) ?>" class="btn btn-primary"><?= __('Unban all IP') ?></a>
        <?php endif; ?>
    </div>
<?php endif; ?>
<div>
    <a href="/admin/"><?= __('Back') ?></a>
</div>
