<?php

use auctionforge\inc\helpers\BS_API;
use auctionforge\inc\helpers\View;
use auctionforge\inc\model\Auction;

global $wp_query;
$usePagination = BS_API::getSettingsValue('use_pagination', 'off');

$perPageDefault = get_option('posts_per_page');
$perPageValues[$perPageDefault] = $perPageDefault;
$perPageValues = array_merge($perPageValues, [
    50 => 50, 100 => 100, 200 => 200
]);
$perPageValues = apply_filters('bp_per_page_values', $perPageValues);
$perPageValues = array_unique($perPageValues);
$perPageField = (isset($_GET['per_page'])) ? $_GET['per_page'] : $perPageDefault;
sort($perPageValues);
?>
<div class="bp-content__pagination bp-from__item bp-lots bp-tools bp-pagination bp-d-flex bp-f-end">
    <?php  if ($usePagination == 'on') { ?>
        <?= get_the_posts_pagination(apply_filters('lots_pagination_settings', Auction::$pagingSettings)); ?>
    <?php } ?>
    <?php if (!empty($wp_query->found_posts)) { ?>
        <?= View::render('templates/parts/chunks/per-page-select', compact('perPageValues', 'perPageField')) ?>
    <?php } ?>
</div>