<?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['filters'])): ?>
    <div class="btn-group mb-3" role="group">
        <?php foreach ($data['filters'] as $filter): ?>
            <a href="<?= $filter['url'] ?>" class="btn btn-outline-secondary <?= ($filter['active'] ? 'active' : '') ?>"><?= $filter['name'] ?></a>
        <?php endforeach; ?>
    </div>
<?php endif; ?>
<?php if (empty($data['items'])): ?>
    <?= $this->fetch(
        'system::app/alert',
        [
            'alert_type' => 'alert-info',
            'alert'      => __('The list is empty'),
        ]
    ) ?>
<?php endif; ?>

<?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="user-avatar mr-2 mr-md-4">
                    <div class="avatar-image rounded-circle overflow-hidden">
                        <img src="<?= $this->avatar($item['id']) ?>" class="img-fluid" alt=".">
                    </div>
                    <div class="user-status <?= $item['user_is_online'] ? 'online' : 'offline' ?> shadow"></div>
                </div>
                <div class="overflow-auto flex-grow-1">
                    <div class="user-name">
                        <?php if (! empty($item['id'])): ?>
                            <a href="/profile/?user=<?= $item['id'] ?>" class="user-login mr-2"><?= $item['name'] ?></a>
                        <?php else: ?>
                            <a class="user-login mr-2"><?= $item['name'] ?></a>
                        <?php endif; ?>
                    </div>
                    <div class="small">
                        <?= $item['count_message'] ?> <?= n__('message', 'messages', $item['count_message']) ?>
                        <?php if ($item['new_count_message'] > 0): ?>
                            , + <?= $item['new_count_message'] ?> <?= n__('unread message', 'unread messages', $item['new_count_message']) ?>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
            <?php if (! empty($item['buttons'])): ?>
                <div class="mt-3">
                    <?php foreach ($item['buttons'] as $button): ?>
                        <a href="<?= $button['url'] ?>" class="btn btn-outline-primary btn-sm"><?= $button['name'] ?></a>
                    <?php endforeach; ?>
                </div>
            <?php endif; ?>
        </div>
        <div class="footer"></div>
    </div>
<?php endforeach; ?>

<div class="mt-4">
    <?php if ($data['total'] > $user->config->kmess): ?>
        <div>
            <?= $data['pagination'] ?>
        </div>
    <?php endif; ?>

    <?php if ($data['total'] > 0): ?>
        <div><?= __('Total:') ?> <?= $data['total'] ?></div>
    <?php endif; ?>
</div>
<div>
    <a href="<?= $data['back_url'] ?>"><?= __('Back') ?></a>
</div>
