<?php
/**
 * Pagination - Show numbered pagination for catalog pages.
 *
 * @package Eronex
 * @since 0.0.1
 * @version 9.3.0
 */

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

$total   = isset( $total ) ? $total : wc_get_loop_prop( 'total_pages' );
$current = isset( $current ) ? $current : wc_get_loop_prop( 'current_page' );
$base    = isset( $base ) ? $base : esc_url_raw( str_replace( 999999999, '%#%', remove_query_arg( 'add-to-cart', get_pagenum_link( 999999999, false ) ) ) );
$format  = isset( $format ) ? $format : '';

if ( $total <= 1 ) {
	return;
}

$pagination = paginate_links(
	/**
	 * Filters the arguments for WooCommerce catalog pagination.
	 *
	 * @since 0.0.1
	 *
	 * @param array $args Arguments passed to paginate_links().
	 */
	apply_filters(
		'woocommerce_pagination_args',
		array(
			'base'      => $base,
			'format'    => $format,
			'add_args'  => false,
			'current'   => max( 1, $current ),
			'total'     => $total,
			'prev_text' => esc_html__( 'Previous', 'eronex' ),
			'next_text' => esc_html__( 'Next', 'eronex' ),
			'type'      => 'list',
			'mid_size'  => 1,
			'end_size'  => 1,
		)
	)
);

if ( $pagination ) {
	echo '<div class="eronex-pagination" aria-label="' . esc_attr__( 'Pagination', 'eronex' ) . '">';
	echo wp_kses_post( $pagination );
	echo '</div>';
}
