<?php

/**
 * This file is part of JohnCMS Content Management System.
 *
 * @copyright JohnCMS Community
 * @license   https://opensource.org/licenses/GPL-3.0 GPL-3.0
 * @link      https://johncms.com JohnCMS Project
 */

/**
 * @var $title
 * @var $page_title
 * @var $data
 */

$this->layout(
    'system::layout/default',
    [
        'title'      => $title,
        'page_title' => $page_title,
    ]
);
?>

<?php if (! empty($data['errors'])): ?>
    <div class="row">
        <div class="col-md-6">
            <?= $this->fetch(
                'system::app/alert',
                [
                    'alert_type' => 'alert-danger',
                    'alert'      => $data['errors'],
                ]
            ) ?>
        </div>
    </div>
<?php endif; ?>

<div class="row">
    <div class="col-md-6">
        <form action="/community/search/" method="get" class="mb-3">
            <label for="search"><?= __('Look for the User') ?></label>
            <div class="input-group">
                <input type="text" name="search" id="search" class="form-control" placeholder="<?= __('Username') ?>" value="<?= $data['search_query'] ?>">
                <div class="input-group-append">
                    <button class="btn btn-outline-secondary" type="submit"><?= __('Search') ?></button>
                </div>
            </div>
            <div class="text-muted mb-2 small"><?= __('The search is performed by Nickname and are case-insensitive.') ?></div>
        </form>
    </div>
</div>


<!-- List of Users -->
<?php if ($data['total']): ?>
    <?php foreach ($data['list'] as $usr): ?>
        <?= $this->fetch('users::user_row', ['item' => $usr]) ?>
    <?php endforeach ?>
<?php else: ?>
    <div class="row">
        <div class="col-md-6">
            <div class="alert alert-info"><?= __('List is empty') ?></div>
        </div>
    </div>
<?php endif ?>

<?php if ($data['total']): ?>
    <div>
        <div><?= __('Total') ?>: <?= $data['total'] ?></div>
        <!-- Page switching -->
        <?php if ($data['total'] > $user->config->kmess): ?>
            <div class="mt-1"><?= $data['pagination'] ?></div>
        <?php endif ?>
    </div>
<?php endif; ?>

<div class="mt-3">
    <div>
        <a href="../search/"><?= __('User Search') ?></a>
    </div>
    <div>
        <a href="../"><?= __('Back') ?></a>
    </div>
</div>
