<?php

/**
 * @var Mobicms\Render\Template\Template $this
 * @var array<int, array<string, mixed>> $items
 * @var int $total
 * @var int $per_page
 * @var string|null $filtered_by
 * @var string $reset_filter
 * @var string|null $del_all_url
 * @var string $pagination
 * @var string $csrf_token
 */

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

<?php if (! empty($filtered_by)): ?>
    <div class="alert alert-warning">
        <?= __('Filtered:') ?> <?= $this->e($filtered_by) ?><br>
        <a href="<?= $this->e($reset_filter) ?>"><?= __('Cancel') ?></a>
    </div>
<?php endif; ?>

<?php if ($total > 0): ?>
    <?php foreach ($items as $item): ?>
        <div class="shadow post-item mb-2">
            <div class="post-header d-flex justify-content-between border-bottom pb-1">
                <div class="d-flex align-items-end">
                    <?php if (! empty($item['user_profile_link'])): ?>
                        <a href="<?= $this->e($item['user_profile_link']) ?>" class="user-login me-2"><?= $this->e($item['user_name']) ?></a>
                    <?php else: ?>
                        <a class="user-login me-2"><?= $this->e($item['user_name']) ?></a>
                    <?php endif; ?>
                    <span class="post-date"><?= $this->e($item['display_date']) ?></span>
                </div>
            </div>
            <div class="post-body d-flex align-items-start pt-3 pb-3">
                <div class="user-avatar me-2 me-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="mb-2 d-flex align-items-center">
                        <span class="me-1"><?= __('Topic:') ?></span>
                        <a href="<?= $this->e($item['topic_url']) ?>"><?= $this->e($item['topic_name']) ?></a>
                    </div>
                    <div class="d-flex align-items-center">
                        <span class="me-1"><?= __('Path:') ?></span>
                        <?php foreach ($item['path'] as $k => $path_item): ?>
                            <?= ($k > 0 ? '<span class="me-1 ms-1"> / </span>' : '') ?>
                            <a href="<?= $this->e($path_item['url']) ?>"><?= $this->e($path_item['name']) ?></a>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
            <div class="post-footer d-flex justify-content-between border-top pt-2">
                <div class="post-user-info d-flex overflow-hidden small align-items-center">
                    <?php if ($user->rights >= $item['rights']): ?>
                        <div class="user-ip me-2">
                            <a href="<?= $this->e($item['search_ip_url']) ?>"><?= $this->e($item['ip']) ?></a>
                            <?php if (! empty($item['ip_via_proxy'])): ?>
                                / <a href="<?= $this->e($item['search_ip_via_proxy_url']) ?>"><?= $this->e($item['ip_via_proxy']) ?></a>
                            <?php endif; ?>
                        </div>
                        <div class="useragent">
                            <span>User-Agent:</span>
                            <span><?= $this->e($item['browser']) ?></span>
                        </div>
                    <?php endif; ?>
                </div>
                <div class="text-nowrap post-actions">
                    <span class="text-muted pe-2 flex-grow-1">
                        <?php if (! empty($item['deleted'])): ?>
                            <?= __('Topic deleted:') ?> <?= $this->e($item['deleted_by']) ?>
                        <?php endif; ?>
                    </span>
                    <span class="pe-1"><?= __('Filter:') ?></span>
                    <?php foreach ($item['buttons'] as $button): ?>
                        <a href="<?= $this->e($button['url']) ?>" class="btn btn-secondary btn-sm me-1"><?= $this->e($button['name']) ?></a>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>
    <?php endforeach ?>
<?php else: ?>
    <div class="row">
        <div class="col-md-6">
            <div class="alert alert-info"><?= __('The list is empty') ?></div>
        </div>
    </div>
<?php endif ?>

<?php if (! empty($del_all_url)): ?>
    <div class="mt-3 mb-2">
        <form action="<?= $this->e($del_all_url) ?>" method="post">
            <input type="hidden" name="csrf_token" value="<?= $csrf_token ?>">
            <input type="submit" value="<?= __('Delete all') ?>" class="btn btn-danger">
        </form>
    </div>
<?php endif ?>

<?php if ($total): ?>
    <div class="mb-1">
        <div><?= __('Total') ?>: <?= $total ?></div>
        <?php if ($total > $per_page): ?>
            <div class="mt-1"><?= $pagination ?></div>
        <?php endif ?>
    </div>
<?php endif ?>

<a href="/admin/forum"><?= __('Back') ?></a>
