<?php
    /**
     * GrayMatter Theme for Bludit
     * Design was copied from a Flatpress Theme by Marc Thibeault
     * Some code copied from Blog-X theme
     *
     * Author:  Rick Hays
     * Date:    2022-12-12
     *
     */
?>

<?php if (empty($content)): ?>
    <div class="mt-4">
        <?php $language->p('No pages found') ?>
    </div>
<?php endif ?>

<?php foreach ($content as $page): ?>
    <div class="home">
        <?php Theme::plugins('pageBegin'); ?>

        <!-- Cover image -->
        <?php if ($page->coverImage()): ?>
            <img class="card-img-top mb-3 rounded-0" alt="Cover Image" src="<?php echo $page->coverImage(); ?>"/>
        <?php endif ?>

        <a href="<?php echo $page->permalink(); ?>">
            <h3><?php echo $page->title(); ?></h3>
        </a>

        <!-- Breaked content -->
        <?php echo $page->contentBreak(); ?>

        <!-- "Read more" button -->
        <?php if ($page->readMore()): ?>
            <a href="<?php echo $page->permalink(); ?>"><?php echo $L->get('[ Read more ]'); ?></a>
        <?php endif ?>

        <h6 class="card-subtitle mb-3 text-muted text-right"><?php echo $page->date(); ?> - <?php echo $L->get('Reading time') . ': ' . $page->readingTime(); ?></h6>
        <h6 class="card-subtitle mb-3 text-muted text-right"><?php echo 'Author: ' . $page->username(); ?></h6>

        <div class="text-right">
            <?php foreach (Theme::socialNetworks() as $key=>$label): ?>
                    <a class="" href="<?php echo $site->{$key}(); ?>" target="_blank">
                        <img height="20" width="20" class="" src="<?php echo DOMAIN_THEME.'img/'.$key.'.svg' ?>" alt="<?php echo $label ?>" />
                        <span class="d-inline d-sm-none"><?php echo $label; ?></span>
                    </a>
            <?php endforeach; ?>
        </div>

        <?php Theme::plugins('pageEnd'); ?>
    </div>
<?php endforeach ?>

<!-- Pagination -->
<?php if (Paginator::numberOfPages()>1): ?>
    <nav class="paginator">
        <ul class="pagination flex-wrap">

            <!-- Previous button -->
            <?php if (Paginator::showPrev()): ?>
                <li class="page-item mr-2">
                    <a class="page-link" href="<?php echo Paginator::previousPageUrl() ?>" tabindex="-1"> &#9668; <?php echo $L->get('Prev'); ?></a>
                </li>
            <?php endif; ?>

            <!-- Home button -->
            <li class="page-item <?php if (Paginator::currentPage()==1) echo 'disabled' ?>">
                <a class="page-link" href="<?php echo Theme::siteUrl() ?>">Home</a>
            </li>

            <!-- Next button -->
            <?php if (Paginator::showNext()): ?>
                <li class="page-item ml-2">
                    <a class="page-link" href="<?php echo Paginator::nextPageUrl() ?>"><?php echo $L->get('Next'); ?> &#9658;</a>
                </li>
            <?php endif; ?>

        </ul>
    </nav>
<?php endif ?>
