<?php
$translate = $this->plugin('translate');

// Do not emit the sort default flags.
$removeQueries = ['page', 'sort_by_default', 'sort_order_default'];
// Do not emit sorts if the corresponding default sort flags are set.
if (isset($query['sort_by_default'])) {
    $removeQueries[] = 'sort_by';
}
if (isset($query['sort_order_default'])) {
    $removeQueries[] = 'sort_order';
}
?>
<nav class="pagination" aria-label="<?php echo $translate('Pagination'); ?>">
<?php if ($totalCount): ?>
    <form method="GET" action="">
        <?php echo $this->queryToHiddenInputs($removeQueries); ?>
        <input type="text" name="page" class="page-input-top" value="<?php echo $currentPage; ?>" size="4" <?php echo ($pageCount == 1) ? 'readonly' : ''; ?> aria-label="<?php echo $translate('Page'); ?>">
        <span class="page-count"><?php echo sprintf($translate('of %s'), $pageCount); ?></span>
    </form>

    <div class="pagination-buttons">
    <?php if ($currentPage != 1): ?>
    <?php echo $this->hyperlink('', $previousPageUrl, ['class' => 'previous o-icon-prev button', 'title' => $translate('Previous'), 'aria-label' => $translate('Previous')]); ?>
    <?php else: ?>
    <span class="previous o-icon-prev button inactive"></span>
    <?php endif; ?>

    <?php if ($currentPage < $pageCount): ?>
    <?php echo $this->hyperlink('', $nextPageUrl, ['class' => 'next o-icon-next button', 'title' => $translate('Next'), 'aria-label' => $translate('Next')]); ?>
    <?php else: ?>
    <span class="next o-icon-next button inactive"></span>
    <?php endif; ?>
    </div>

    <?php
    $from = $offset + 1;
    $to = ($currentPage < $pageCount) ? $offset + $perPage : $totalCount;
    ?>
    <span class="row-count"><?php echo sprintf($translate('%1$s–%2$s of %3$s'), $from, $to, $totalCount); ?></span>
<?php else: ?>
    <?php echo $translate('0 results'); ?>
<?php endif; ?>
</nav>
