<?php

/**
 * @var $title
 * @var $page_title
 * @var $current_section
 * @var $user
 * @var $articles Illuminate\Contracts\Pagination\LengthAwarePaginator
 * @var $sections \Blog\Models\BlogSection
 */

$this->layout('system::layout/default');
?>
<?php if ($user->rights >= 9): ?>
    <div class="mb-3 mt-n1">
        <a href="/blog/admin/" class="btn btn-outline-danger btn-sm"><?= __('Admin panel') ?></a>
    </div>
<?php endif ?>
<div class="row">
    <div class="col-12 col-xl-9">
        <?php if ($articles->count() > 0): ?>
            <?php foreach ($articles as $article): ?>
                <?php /** @var $article \Blog\Models\BlogArticle */ ?>
                <div class="card border-0 mb-2 shadow">
                    <div class="card-body">
                        <h3 class="card-title mb-0"><a href="<?= $article->url ?>"><?= $article->name ?></a></h3>
                        <?php if ($article->preview_text_safe): ?>
                            <p class="card-text mt-2"><?= $article->preview_text_safe ?></p>
                        <?php endif ?>
                    </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>
    <div class="col-12 col-xl-3">
        <?php if ($sections->count() > 0): ?>
            <h3 class="pl-3"><?= __('Categories') ?></h3>
            <nav class="nav flex-column">
                <?php foreach ($sections as $section): ?>
                    <?php /** @var $section \Blog\Models\BlogSection */ ?>
                    <a class="nav-link" href="<?= $section->url ?>"><?= $section->name ?></a>
                <?php endforeach; ?>
            </nav>
        <?php endif; ?>
    </div>
</div>

<?php $this->push('styles') ?>
    <link rel="stylesheet" href="<?= $this->asset('blog/css/blog.css', true) ?>">
<?php $this->stop(); ?>
<?php $this->push('scripts') ?>
    <script async charset="utf-8" src="//cdn.embedly.com/widgets/platform.js"></script>
    <script>
        document.querySelectorAll('oembed[url]').forEach(element => {
            const anchor = document.createElement('a');
            anchor.setAttribute('href', element.getAttribute('url'));
            anchor.className = 'embedly-card';
            element.appendChild(anchor);
        });
    </script>
<?php $this->stop(); ?>
