<?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 $data
 */

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

<?php if (! $config['mod_lib']): ?>
    <div class="alert alert-danger border-0 shadow">
        <?= __('Library is closed') ?>
    </div>
<?php endif; ?>
<div class="mb-2 mt-n2">
    <?php if (! empty($new)): ?>
        <a href="/library/new" class="btn btn-outline-primary btn-sm me-1 mt-1">
            <?= __('New Articles') ?> <span class="badge text-bg-secondary rounded-pill ms-1"><?= $new ?></span>
        </a>
    <?php endif; ?>
    <a href="/library/search" class="btn btn-outline-primary btn-sm me-1 mt-1"><?= __('Search') ?></a>
    <?php /* <a href="?act=tagcloud" class="btn btn-outline-primary btn-sm me-1"><?= __('Tag Cloud') ?></a> */ ?>
    <a href="/library/top" class="btn btn-outline-primary btn-sm me-1 mt-1"><?= __('Rating articles') ?></a>
    <a href="/library/latest-comments" class="btn btn-outline-primary btn-sm me-1 mt-1"><?= __('Latest comments') ?></a>
</div>

<?php if ($total) : ?>
    <!-- Listing Sections -->
    <?php foreach ($list as $main) : ?>
        <div class="forum-section">
            <div class="section-header d-flex justify-content-between <?= (empty($category['desc']) ? 'border-0 pb-0' : '') ?>">
                <div class="d-flex align-items-center">
                    <a href="<?= $main['url'] ?>" class="text-dark-brown"><?= $main['name'] ?></a>
                    <span class="badge rounded-pill counter-badge border ms-3"><?= $main['libCounter'] ?></span>
                </div>
            </div>
            <?php if (! empty($main['description'])): ?>
                <div class="small mt-1 text-muted">
                    <div><?= $main['description'] ?></div>
                </div>
            <?php endif; ?>
            <?php if ($admin): ?>
                <div class="small pt-1">
                    <?= $main['sectionListAdminPanel'] ?>
                </div>
            <?php endif; ?>
        </div>
    <?php endforeach; ?>
<?php else : ?>
    <div class="alert alert-info shadow border-0"><?= __('The list is empty') ?></div>
<?php endif; ?>

<?php if ($admin) : ?>
    <div class="mt-3">
        <a href="/library/section/create" class="btn btn-primary"><?= __('Create Section') ?></a>
        <?php if ($premod) : ?>
            <a href="/library/premod" class="btn btn-warning ms-2">
                <?= __('Moderation Articles') ?> <span class="badge text-bg-dark rounded-pill ms-1"><?= $countPremod ?></span>
            </a>
        <?php endif; ?>
    </div>
<?php endif; ?>
