<?php

/**
 * Шаблон постраничной навигации.
 *
 * Формат элементов (Johncms\Http\Pagination\Pagination):
 *   ['type' => prev|page|ellipsis|next, 'page' => int|null, 'url' => string|null, 'active' => bool]
 *
 * @var array[] $items
 */

use Johncms\Http\Pagination\Pagination;

?>
<?php if (! empty($items)): ?>
    <nav>
        <ul class="pagination">
            <?php foreach ($items as $item): ?>
                <?php if ($item['type'] === Pagination::TYPE_PREV): ?>
                    <?php if ($item['url'] !== null): ?>
                        <li class="page-item">
                            <a class="page-link" href="<?= $this->e($item['url']) ?>" rel="prev" aria-label="Previous page">&laquo;</a>
                        </li>
                    <?php else: ?>
                        <li class="page-item disabled" aria-disabled="true" aria-label="Previous">
                            <span class="page-link" aria-hidden="true">&laquo;</span>
                        </li>
                    <?php endif ?>
                <?php elseif ($item['type'] === Pagination::TYPE_NEXT): ?>
                    <?php if ($item['url'] !== null): ?>
                        <li class="page-item">
                            <a class="page-link" href="<?= $this->e($item['url']) ?>" rel="next" aria-label="Next page">&raquo;</a>
                        </li>
                    <?php else: ?>
                        <li class="page-item disabled" aria-disabled="true" aria-label="Next">
                            <span class="page-link" aria-hidden="true">&raquo;</span>
                        </li>
                    <?php endif ?>
                <?php elseif ($item['type'] === Pagination::TYPE_ELLIPSIS): ?>
                    <li class="page-item disabled" aria-disabled="true"><span class="page-link">...</span></li>
                <?php elseif ($item['active']): ?>
                    <li class="page-item active" aria-current="page"><span class="page-link"><?= $item['page'] ?></span></li>
                <?php else: ?>
                    <li class="page-item"><a class="page-link" href="<?= $this->e($item['url']) ?>"><?= $item['page'] ?></a></li>
                <?php endif ?>
            <?php endforeach ?>
        </ul>
    </nav>
<?php endif ?>
