<?php

/**
 * @var Mobicms\Render\Template\Template $this
 * @var string $search
 * @var array<int, array<string, mixed>> $items
 * @var list<string> $errors
 * @var array<int, array{url: string, name: string, active: bool}> $filters
 * @var int $total
 * @var int $per_page
 * @var string $pagination
 */

$this->layout('system::layout/default');
?>
<div class="btn-group mb-3" role="group">
    <?php foreach ($filters as $filter): ?>
        <a href="<?= $this->e($filter['url']) ?>" class="btn btn-outline-secondary <?= $filter['active'] ? 'active' : '' ?>"><?= $this->e($filter['name']) ?></a>
    <?php endforeach ?>
</div>

<div class="row">
    <div class="col-md-6">
        <form action="/admin/ip-search" method="get" class="mb-3">
            <label for="search"><?= __('Search IP') ?></label>
            <div class="input-group">
                <input type="text" name="search" id="search" class="form-control" placeholder="<?= __('Search IP') ?>" value="<?= $this->e($search) ?>">
                <div class="input-group-append">
                    <button class="btn btn-outline-secondary" type="submit"><?= __('Search') ?></button>
                </div>
            </div>
            <div class="text-muted mb-2 small">
                <b><?= __('Sample queries:') ?></b><br>
                <div><span class="fw-bold">10.5.7.1</span> &mdash; <?= __('Search for a single address') ?></div>
                <div><span class="fw-bold">10.5.7.1-10.5.7.100</span> &mdash; <?= __('Search a range address (forbidden to use mask symbol *)') ?></div>
                <div><span class="fw-bold">10.5.*.*</span> &mdash; <?= __('Search mask. Will be found all subnet addresses starting with 0 and ending with 255') ?></div>
            </div>
        </form>
    </div>
</div>

<?php foreach ($errors as $error): ?>
    <?= $this->fetch('system::app/alert', ['alert_type' => 'alert-danger', 'alert' => $this->e($error)]) ?>
<?php endforeach ?>

<?php if ($errors === [] && $search !== '' && $items === []): ?>
    <?= $this->fetch('system::app/alert', ['alert_type' => 'alert-info', 'alert' => __('At your request, nothing found')]) ?>
<?php elseif ($items !== []): ?>
    <h2><?= __('Search results') ?></h2>
    <?php foreach ($items as $item): ?>
        <?= $this->fetch('admin::user_row', ['item' => $item]) ?>
    <?php endforeach ?>
<?php endif ?>

<div class="mt-4">
    <?php if ($total > $per_page): ?>
        <div><?= $pagination ?></div>
    <?php endif ?>
    <?php if ($total > 0): ?>
        <div><?= __('Total:') ?> <?= $total ?></div>
    <?php endif ?>
</div>
<div>
    <a href="/admin"><?= __('Back') ?></a>
</div>
