<?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 $files
 * @var $buttons
 * @var $urls
 */

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

<?php if (! $config['mod_down_comm']): ?>
    <div class="alert alert-danger border-0 shadow">
        <?= __('Comments are disabled') ?>
    </div>
<?php endif; ?>

<!-- Отображаем комментарии -->
<?php if (empty($data['items'])): ?>
    <div class="alert alert-info"><?= __('The list is empty') ?></div>
<?php else: ?>
    <?php foreach ($data['items'] as $item): ?>
        <div class="new_post-item mb-2">
            <div class="new_post-header d-flex justify-content-between">
                <div class="post-user">
                    <a href="/profile/?user=<?= $item['user_id'] ?>">
                        <div class="avatar">
                            <img src="<?= $this->avatar($item['user_id']) ?>" class="img-fluid" alt=".">
                        </div>
                    </a>
                </div>
                <div class="flex-grow-1 post-user d-flex flex-wrap overflow-hidden d-flex align-items-center">
                    <div class="w-100">
                        <a href="/profile/?user=<?= $item['user_id'] ?>"><span class="user-name d-inline mr-2"><?= $item['name'] ?></span></a>
                        <span class="post-meta d-inline mr-2"><?= $item['created'] ?></span>
                        <?php if (! empty($item['edit_count'])): ?>
                            <div class="post-meta d-inline mr-2"
                                 data-toggle="tooltip"
                                 data-placement="top"
                                 data-html="true"
                                 title="<?= __('Edited:') ?> <?= $item['editor_name'] ?> <br> (<?= $item['edit_time'] ?>) [<?= $item['edit_count'] ?>]">
                                <?= __('Edited') ?>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
            <div class="post-body mt-2 border-top pt-2 pb-2">
                <?= $item['post_text'] ?>
                <?php if (! empty($item['reply_text'])): ?>
                    <div class="alert alert-warning mt-2 mb-2">
                        <b><a href="<?= $item['reply_author_url'] ?>"><?= $item['reply_author_name'] ?></a></b> <?= $item['reply_time'] ?><br>
                        <?= $item['reply_text'] ?>
                    </div>
                <?php endif; ?>
            </div>
            <div class="small">
                <?php if (! empty($item['file_url'])): ?>
                    <a href="<?= $item['file_url'] ?>" class="mr-2"><?= $item['rus_name'] ?></a>
                <?php endif; ?>
                <?php if (! empty($item['comments_url'])): ?>
                    <a href="<?= $item['comments_url'] ?>"><?= __('Comments') ?></a>
                <?php endif; ?>
            </div>

            <?php if ($user->rights || ! empty($item['edit_count'])): ?>
                <div class="post-footer d-flex justify-content-between pt-2">
                    <div class="overflow-hidden">
                        <?php if ($user->rights): ?>
                            <div class="post-meta d-flex">
                                <div class="user-ip mr-2">
                                    <a href="<?= $item['search_ip_url'] ?>"><?= $item['ip'] ?></a>
                                    <?php if (! empty($item['ip_via_proxy'])): ?>
                                        / <a href="<?= $item['search_ip_via_proxy_url'] ?>"><?= $item['ip_via_proxy'] ?></a>
                                    <?php endif; ?>
                                </div>
                                <div class="useragent">
                                    <span><?= $item['user_agent'] ?></span>
                                </div>
                            </div>
                        <?php endif; ?>
                    </div>
                    <div class="d-flex">
                        <?php if (! empty($item['edit_url']) || ! empty($item['delete_url'])): ?>
                            <div class="dropdown ml-3">
                                <div class="cursor-pointer" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                    <svg class="icon text-primary">
                                        <use xlink:href="<?= $this->asset('icons/sprite.svg') ?>?1#more_horizontal"/>
                                    </svg>
                                </div>
                                <div class="dropdown-menu dropdown-menu-right">
                                    <?php if (! empty($item['edit_url'])): ?>
                                        <a href="<?= $item['edit_url'] ?>" class="dropdown-item"><?= __('Edit') ?></a>
                                    <?php endif; ?>
                                    <?php if (! empty($item['delete_url'])): ?>
                                        <a href="<?= $item['delete_url'] ?>" class="dropdown-item"><?= __('Delete') ?></a>
                                    <?php endif; ?>
                                </div>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            <?php endif; ?>
        </div>
    <?php endforeach; ?>

    <?php if (! empty($data['pagination'])): ?>
        <div class="mt-3">
            <?= $data['pagination'] ?>
        </div>
    <?php endif; ?>
<?php endif; ?>

<div class="mt-3">
    <a href="<?= $urls['downloads'] ?>"><?= __('Downloads') ?></a>
</div>
