<?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 $settings_forum
 * @var $topic
 */

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

<div class="new_post-item border-bottom shadow mb-2 <?= $post['deleted'] ? ' deleted-post' : '' ?>">
    <div class="new_post-header d-flex justify-content-between">
        <div class="post-user">
            <?php if (! empty($post['user_profile_link'])): ?>
                <a href="<?= $post['user_profile_link'] ?>">
                    <div class="avatar">
                        <img src="<?= $this->avatar($post['user_id']) ?>" class="img-fluid" alt=".">
                    </div>
                </a>
            <?php else: ?>
                <div class="avatar">
                    <img src="<?= $this->avatar($post['user_id']) ?>" class="img-fluid" alt=".">
                </div>
            <?php endif; ?>
            <span class="user-status <?= $post['user_is_online'] ? 'online' : 'offline' ?> shadow"></span>
            <?php if (! empty($post['user_rights_name'])): ?>
                <div class="post-of-user"
                     data-toggle="tooltip"
                     data-placement="top"
                     data-html="true"
                     title="<?= $post['user_rights_name'] ?>">
                    <svg class="icon-post">
                        <use xlink:href="<?= $this->asset('icons/sprite.svg') ?>?4#check"/>
                    </svg>
                </div>
            <?php endif ?>
        </div>
        <div class="flex-grow-1 post-user d-flex flex-wrap overflow-hidden d-flex align-items-center">
            <div class="w-100">
                <?php if (! empty($post['user_profile_link'])): ?>
                    <a href="<?= $post['user_profile_link'] ?>"><span class="user-name d-inline mr-2"><?= $post['user_name'] ?></span></a>
                <?php else: ?>
                    <div class="user-name d-inline mr-2"><?= $post['user_name'] ?></div>
                <?php endif; ?>
                <span class="post-meta d-inline mr-2"><?= $post['post_time'] ?></span>
                <?php if (! empty($post['edit_count'])): ?>
                    <div class="post-meta d-inline mr-2"
                         data-toggle="tooltip"
                         data-placement="top"
                         data-html="true"
                         title="<?= __('Edited:') ?> <?= $post['editor_name'] ?> <br> (<?= $post['edit_time'] ?>) [<?= $post['edit_count'] ?>]">
                        <?= __('Edited') ?>
                    </div>
                <?php endif; ?>
            </div>
            <?php if (! empty($post['status'])): ?>
                <div class="overflow-hidden text-nowrap text-dark-brown overflow-ellipsis small">
                    <span class="font-weight-bold"><?= $post['status'] ?></span>
                </div>
            <?php endif ?>
        </div>
    </div>
    <div class="post-body mt-2 border-top pt-2 pb-2">
        <?= $post['post_text'] ?>
    </div>
    <?php if (! empty($post['files'])): ?>
        <!-- Files block -->
        <div class="mt-3 pb-1">
            <div class="font-weight-bold pb-1"><?= __('Attached files') ?>:</div>
            <div class="d-flex flex-wrap image-gallery">
                <?php foreach ($post['files'] as $file): ?>
                    <div class="attached-file pr-3 d-flex flex-column justify-content-between">
                        <div class="d-flex justify-content-center align-items-center">
                            <?php if (! empty($file['file_preview'])): ?>
                                <a href="<?= $file['file_url'] ?>" class="gallery-item" data-source="<?= $file['file_url'] ?>" title="<?= $file['filename'] ?>">
                                    <img src="<?= $file['file_preview'] ?>" class="img-thumbnail thumb-limit-height" alt="<?= $file['filename'] ?>">
                                </a>
                            <?php else: ?>
                                <a href="<?= $file['file_url'] ?>">
                                    <svg class="icon attachment-icon">
                                        <use xlink:href="<?= $this->asset('icons/sprite.svg') ?>#file"/>
                                    </svg>
                                </a>
                            <?php endif; ?>
                        </div>
                        <div class="pt-1">
                            <div class="text-muted small d-flex flex-wrap justify-content-center">
                                <div class="text-nowrap pr-1">
                                    <svg class="icon downloads-icon">
                                        <use xlink:href="<?= $this->asset('icons/sprite.svg') ?>#download"/>
                                    </svg>
                                    <?= $file['dlcount'] ?>
                                </div>
                                <div>(<?= $file['file_size'] ?>)</div>
                            </div>
                            <div class="file-name">
                                <a href="<?= $file['file_url'] ?>" title="<?= $file['filename'] ?>"><?= $file['filename'] ?></a>
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>
    <?php endif; ?>
    <div class="post-footer d-flex justify-content-between mt-2">
        <div class="overflow-hidden">
            <?php if ($user->rights): ?>
                <div class="post-meta d-flex">
                    <div class="user-ip mr-2">
                        <a href="<?= $post['search_ip_url'] ?>"><?= $post['ip'] ?></a>
                        <?php if (! empty($post['ip_via_proxy'])): ?>
                            / <a href="<?= $post['search_ip_via_proxy_url'] ?>"><?= $post['ip_via_proxy'] ?></a>
                        <?php endif; ?>
                    </div>
                    <div class="useragent">
                        <span><?= $post['user_agent'] ?></span>
                    </div>
                </div>
            <?php endif; ?>
        </div>
        <div class="d-flex">
            <?php if (! empty($post['reply_url'])): ?>
                <div class="ml-3">
                    <a href="<?= $post['reply_url'] ?>"><?= __('Reply') ?></a>
                </div>
            <?php endif; ?>
            <?php if (! empty($post['quote_url'])): ?>
                <div class="ml-3">
                    <a href="<?= $post['quote_url'] ?>"><?= __('Quote') ?></a>
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<div class="mt-2">
    <a href="<?= $back_to_topic ?>"><?= __('Back to topic') ?></a><br>
    <a href="/forum/"><?= __('Forum') ?></a>
</div>
