<?php
/**
 * The template to display pagination.
 *
 * This template can be overridden by copying it to
 * your-child-theme/views/pagination.php.
 *
 * @package MadeByAura\Prime
 * @author  MadeByAura.com
 *
 * @param array $args
 */

namespace MadeByAura\Prime;

defined( 'ABSPATH' ) || die();

// Global variables.
global $wp_query;

// Set variables.
$current_page = absint( get_query_var( 'paged' ) ) ?: 1;
$total_pages  = absint( $wp_query->max_num_pages );
$prev_url     = '';
$next_url     = '';

// Set previous page url, if current page is greater than 1.
if ( $current_page > 1 ) {
	$prev_url = get_previous_posts_page_link( false );
}

// Set next page url, if current page is less than total pages.
if ( $current_page < $total_pages ) {
	$next_url = get_next_posts_page_link();
}

// Do not proceed, if both previous and next urls are empty.
if ( ! $prev_url && ! $next_url ) {
	return;
}
?>

<div class="aura-pagination">
	<?php if ( $prev_url ) : ?>
		<a class="aura-pagination__prev" href="<?php echo esc_url( $prev_url ); ?>">
			<?php echo esc_html__( 'Previous Page', 'aura-prime' ); ?>
		</a>
	<?php endif; ?>

	<?php if ( $next_url ) : ?>
		<a class="aura-pagination__next" href="<?php echo esc_url( $next_url ); ?>">
			<?php echo esc_html__( 'Next Page', 'aura-prime' ); ?>
		</a>
	<?php endif; ?>
</div>
