<?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 $blocklist
 * @var $total
 * @var $nav_active
 */

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

<?= $this->fetch('mail::nav', ['active' => $nav_active ?? '']) ?>

<?php if ($total === 0): ?>
    <?= $this->fetch(
        'system::app/alert',
        [
            'alert_type' => 'alert-info',
            'alert'      => __('The list is empty'),
        ]
    ) ?>
<?php else: ?>
    <?php foreach ($blocklist as $contact): ?>
        <?php $user = $contact->contactUser; ?>
        <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 me-2 me-md-4">
                        <div class="avatar-image rounded-circle overflow-hidden">
                            <img src="<?= $this->avatar($user->id) ?>" class="img-fluid" alt=".">
                        </div>
                        <div class="user-status <?= $user->is_online ? 'online' : 'offline' ?>"></div>
                    </div>
                    <div class="overflow-auto flex-grow-1">
                        <div class="d-flex flex-wrap align-items-center justify-content-between mb-2">
                            <div class="user-name">
                                <a href="/profile/<?= $user->id ?>" class="text-decoration-none fw-bold"><?= $this->e($user->name) ?></a>
                            </div>
                            <div class="text-muted small">
                                <?= $tools->displayDate($contact->time) ?>
                            </div>
                        </div>
                        <div class="user-info small text-muted">
                            <?= __('User since:') ?> <?= $tools->displayDate($user->datereg) ?>
                        </div>
                        <div class="mt-3">
                            <a href="/mail/write/<?= $user->id ?>" class="btn btn-sm btn-outline-primary"><?= __('Correspondence') ?></a>
                            <a href="/mail/delete-contact/<?= $user->id ?>" class="btn btn-sm btn-outline-danger"><?= __('Delete') ?></a>
                            <a href="/mail/unblock/<?= $user->id ?>" class="btn btn-sm btn-outline-warning"><?= __('Unblock') ?></a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    <?php endforeach; ?>

    <?php if (isset($pagination)): ?>
        <div class="mt-3">
            <?= $pagination ?>
        </div>
    <?php endif; ?>
<?php endif; ?>