<?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,
    ]
);
?>
<h4><?= __('User:') ?> <?= $data['user_name'] ?></h4>
<!-- List of Users -->
<?php if ($data['total']): ?>
    <?php foreach ($data['items'] as $item): ?>
        <div class="user-row card shadow border-0 mb-2">
            <div class="card-body">
                <div class="d-flex align-items-start">
                    <div class="overflow-auto flex-grow-1">
                        <div class="user-name d-flex align-items-center">
                            <span class="user-login mr-2"><?= $item['ban_type_name'] ?></span>
                            <span class="text-muted"><?= $item['ban_started'] ?></span>
                            <?php if (! empty($item['remain'])): ?>
                                <span class="badge badge-danger badge-pill ml-auto"><?= __('Active') ?></span>
                            <?php endif ?>
                        </div>
                        <div>
                            <?= $item['reason_formatted'] ?>
                        </div>
                        <div class="text-muted small mb-2">
                            <?php if ($user->rights > 0): ?>
                                <div>
                                    <?= __('Blocked by:') ?>: <?= $item['ban_who'] ?>
                                </div>
                            <?php endif ?>
                            <div>
                                <?= __('Time:') ?> <?= $item['time_name'] ?>
                            </div>
                            <?php if (! empty($item['remain'])): ?>
                                <div>
                                    <?= __('Remains:') ?> <?= $item['remain'] ?>
                                </div>
                            <?php endif ?>
                        </div>
                    </div>
                </div>
                <div>
                    <?php if (! empty($item['buttons'])): ?>
                        <?php foreach ($item['buttons'] as $button): ?>
                            <a href="<?= $button['url'] ?>" class="btn btn-primary btn-sm"><?= $button['name'] ?></a>
                        <?php endforeach; ?>
                    <?php endif ?>
                </div>
            </div>
        </div>
    <?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"><?= $pagination ?></div>
        <?php endif ?>
    </div>
<?php endif; ?>

<?php if (! empty($data['clear_history_url'])): ?>
    <div class="mt-2">
        <a href="<?= $data['clear_history_url'] ?>" class="btn btn-danger btn-sm"><?= __('Clear history') ?></a>
    </div>
<?php endif; ?>

<div class="mt-3">
    <div>
        <a href="<?= $data['back_url'] ?>"><?= __('Back') ?></a>
    </div>
</div>
