<?php

/**
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
 * @copyright Metaways Infosystems GmbH, 2012
 * @copyright Aimeos (aimeos.org), 2015-2025
 */

$enc = $this->encoder();

$multi = $this->config( 'client/html/catalog/multiroute', false );
$linkKey = $multi && $this->param( 'path' ) || $this->param( 'f_catid' ) ? 'client/html/catalog/tree/url' : 'client/html/catalog/lists/url';
$sort = $this->param( 'f_sort', $this->config( 'client/html/catalog/lists/sort', 'relevance' ) );
$infiniteScroll = $this->config( 'client/html/catalog/lists/infinite-scroll', false );
$params = $this->get( 'params', [] );

$sortname = ltrim( $sort, '-' );
$nameDir = $priceDir = '';

if( $sort === 'name' ) {
	$nameSort = $this->translate( 'client', '▼ Name' ); $nameDir = '-';
} else if( $sort === '-name' ) {
	$nameSort = $this->translate( 'client', '▲ Name' );
} else {
	$nameSort = $this->translate( 'client', 'Name' );
}

if( $sort === 'price' ) {
	$priceSort = $this->translate( 'client', '▼ Price' ); $priceDir = '-';
} else if( $sort === '-price' ) {
	$priceSort = $this->translate( 'client', '▲ Price' );
} else {
	$priceSort = $this->translate( 'client', 'Price' );
}


?>
<nav class="pagination">

	<div class="sort" aria-label="<?= $enc->attr( $this->translate( 'client', 'Sort by' ) ) ?>">
		<span><?= $enc->html( $this->translate( 'client', 'Sort by' ), $enc::TRUST ) ?>:</span>
		<ul>
			<li>
				<?php $url = $this->link( $linkKey, ['f_sort' => 'relevance'] + $params ) ?>
				<a class="option-relevance <?= ( $sort === 'relevance' ? 'active' : '' ) ?>" href="<?= $enc->attr( $url ) ?>">
					<?= $enc->html( $this->translate( 'client', 'Relevance' ), $enc::TRUST ) ?>
				</a>
			</li>
			<li>
				<?php $url = $this->link( $linkKey, ['f_sort' => '-ctime'] + $params ) ?>
				<a class="option-ctime <?= ( $sort === '-ctime' ? 'active' : '' ) ?>" href="<?= $enc->attr( $url ) ?>">
					<?= $enc->html( $this->translate( 'client', 'Latest' ), $enc::TRUST ) ?>
				</a>
			</li>
			<li>
				<?php $url = $this->link( $linkKey, ['f_sort' => $nameDir . 'name'] + $params ) ?>
				<a class="option-name <?= ( $sortname === 'name' ? 'active' : '' ) ?>" href="<?= $enc->attr( $url ) ?>">
					<?= $enc->html( $nameSort, $enc::TRUST ) ?>
				</a>
			</li>
			<li>
				<?php $url = $this->link( $linkKey, ['f_sort' => $priceDir . 'price'] + $params ) ?>
				<a class="option-price <?= ( $sortname === 'price' ? 'active' : '' ) ?>" href="<?= $enc->attr( $url ) ?>">
					<?= $enc->html( $priceSort, $enc::TRUST ) ?>
				</a>
			</li>
			<li>
				<?php $url = $this->link( $linkKey, ['f_sort' => '-rating'] + $params ) ?>
				<a class="option-rating <?= ( $sort === '-rating' ? 'active' : '' ) ?>" href="<?= $enc->attr( $url ) ?>">
					<?= $enc->html( $this->translate( 'client', 'Rating' ), $enc::TRUST ) ?>
				</a>
			</li>
		</ul>
	</div>

	<?php if( !$infiniteScroll && $this->last > 1 ) : ?>
		<div class="browser" aria-label="<?= $enc->attr( $this->translate( 'client', 'Go to page' ) ) ?>">

			<?php $url = $this->link( $linkKey, ['l_page' => 1] + $params ) ?>
			<a class="first" href="<?= $enc->attr( $url ) ?>" title="<?= $enc->attr( $this->translate( 'client', 'First' ) ) ?>">
				<?= $enc->html( $this->translate( 'client', '◀◀' ), $enc::TRUST ) ?>
			</a>

			<?php $url = $this->link( $linkKey, ['l_page' => $this->prev] + $params ) ?>
			<a class="prev" href="<?= $enc->attr( $url ) ?>" title="<?= $enc->attr( $this->translate( 'client', 'Previous' ) ) ?>">
				<?= $enc->html( $this->translate( 'client', '◀' ), $enc::TRUST ) ?>
			</a>

			<span><?= $enc->html( sprintf( $this->translate( 'client', 'Page %1$d of %2$d' ), $this->current, $this->last ) ) ?></span>

			<?php $url = $this->link( $linkKey, ['l_page' => $this->next] + $params ) ?>
			<a class="next" href="<?= $enc->attr( $url ) ?>" title="<?= $enc->attr( $this->translate( 'client', 'Next' ) ) ?>">
				<?= $enc->html( $this->translate( 'client', '▶' ), $enc::TRUST ) ?>
			</a>

			<?php $url = $this->link( $linkKey, ['l_page' => $this->last] + $params ) ?>
			<a class="last" href="<?= $enc->attr( $url ) ?>" title="<?= $enc->attr( $this->translate( 'client', 'Last' ) ) ?>">
				<?= $enc->html( $this->translate( 'client', '▶▶' ), $enc::TRUST ) ?>
			</a>

		</div>
	<?php endif ?>

</nav>
