<?php

/**
 * @var $title
 * @var $page_title
 * @var $current_section
 * @var $user
 * @var $articles \News\Models\NewsArticle[]
 * @var $sections \News\Models\NewsSection
 */

$this->layout('system::layout/default');
?>
<?php if ($user->rights >= 9): ?>
    <div class="mb-3 mt-n1">
        <a href="/admin/news/" class="btn btn-outline-danger btn-sm"><?= __('Admin panel') ?></a>
    </div>
<?php endif ?>

<div class="mb-3">
    <form action="/news/search/" method="get" class="search-in-nav news-search mb-3" style="max-width: 500px;">
        <div class="input-with-inner-btn">
            <input name="query" type="text" minlength="4" placeholder="<?= __('Search query') ?>" class="form-control pr-5 border-radius-12">
            <button type="submit" name="submit" value="1" class="btn icon-button">
                <svg class="icon">
                    <use xlink:href="<?= $this->asset('icons/sprite.svg') ?>#search"></use>
                </svg>
            </button>
        </div>
    </form>
    <?php if ($sections->count() > 0): ?>
        <nav class="nav">
            <?php foreach ($sections as $section): ?>
                <a class="nav-link pl-0" href="<?= $section->url ?>"><?= $section->name ?></a>
            <?php endforeach; ?>
        </nav>
    <?php endif; ?>
</div>

<div>
    <?php if ($articles->count() > 0): ?>
        <?php foreach ($articles as $article): ?>
            <div class="new_post-item without_avatar">
                <a href="<?= $article->url ?>" class="post-title"><?= $article->name ?></a>
                <?php if ($article->preview_text_safe): ?>
                    <div class="post-body pt-2"><?= $article->preview_text_safe ?></div>
                <?php endif ?>
                <div class="d-flex">
                    <div class="text-muted forum-view-counter">
                        <svg class="icon download-button-icon mt-n1 mr-1">
                            <use xlink:href="<?= $this->asset('icons/sprite.svg') ?>#rating"/>
                        </svg>
                        <?php if ($article->rating > 0): ?>
                            <span class="text-success font-weight-bold"><?= $article->rating ?></span>
                        <?php elseif ($article->rating < 0): ?>
                            <span class="text-danger font-weight-bold"><?= $article->rating ?></span>
                        <?php else: ?>
                            <span class="font-weight-bold"><?= $article->rating ?></span>
                        <?php endif; ?>
                    </div>
                    <div class="text-muted forum-view-counter ml-3">
                        <svg class="icon download-button-icon mt-n1 mr-1">
                            <use xlink:href="<?= $this->asset('icons/sprite.svg') ?>#eye"/>
                        </svg>
                        <?= (int) $article->view_count ?>
                    </div>
                    <div class="text-muted forum-view-counter ml-3">
                        <svg class="icon download-button-icon mr-1">
                            <use xlink:href="<?= $this->asset('icons/sprite.svg') ?>#forum"/>
                        </svg>
                        <?= $article->comments_count ?>
                    </div>
                </div>
            </div>
        <?php endforeach; ?>
        <div class="mt-3">
            <?= $articles->render() ?>
        </div>
    <?php else: ?>
        <div class="alert alert-info"><?= __('The list is empty') ?></div>
    <?php endif; ?>
</div>
