<?php

/**
 * Pagination display provider
 *
 * This template can be overridden by copying it to yourtheme/domain-for-sale/templates/pagination.php
 *
 * @package    domain-for-sale
 * @subpackage domain-for-sale/public
 */


if (! defined('ABSPATH')) {
    exit;
}

if ($show_domain_pagination) {

    $domain_found   = (int) $domain_found;
    $domain_limit    = !empty($listing_template_options['domain_limit']) ? $listing_template_options['domain_limit'] : 100000;
    $domain_limit    = ($domain_limit > 0 && $domain_found > $domain_limit) ? $domain_limit : $domain_found;
    $domain_per_page = isset($listing_template_options['domain_per_page']) ? $listing_template_options['domain_per_page'] : 12;
    $domain_per_page = ($domain_per_page > $domain_limit) ? $domain_limit : $domain_per_page;

    $domain_limit = (int) $domain_limit;
    if ($domain_limit < 1) {
        $pages = 0;
    } else {
        if (!$domain_limit) {
            return;
        }
        $max_num_pages = ceil($domain_limit / $domain_per_page);
        $pages = (int) $max_num_pages;
    }

    if ($pages > 1) {
        $page_current     = max(1, get_query_var('paged'));

        $paged_var    = 'paged' . $listing_gl_id;
        $page_current = (!empty($_GET["$paged_var"])) ? sanitize_text_field(wp_unslash($_GET["$paged_var"])) : 1;

        $page_links = paginate_links(
            array(
                'format'    => '?' . $paged_var . '=%#%',
                'current'   => $page_current,
                'total'     => $pages,
                'show_all'  => false,
                'prev_next' => true,
                'end_size'  => 2,
                'mid_size'  => 1,
                'type'      => 'array',
                'prev_text' => '<i class="icofont-rounded-left"></i>',
                'next_text' => '<i class="icofont-rounded-right"></i>',
            )
        );
        echo implode($page_links);
    }
}
