<?php

/**
 * Pagination display provider
 *
 * This template can be overridden by copying it to yourtheme/eventful-por-elementor/templates/pagination.php
 *
 * @package    eventful-for-elementor
 * @subpackage eventful-for-elementor/src/Frontend/templates
 */

use ThemeAtelier\EventfulForElementor\Frontend\Helpers\EventfulForElementorLoopHtml;

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


// Verify nonce
if (isset($_POST['nonce']) && !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ta_efpe_nonce')) {
	wp_die("Invalid nonce");
}

// Initialize settings array
$efpe_settings = isset($_POST['efpe_settings']) ? $_POST['efpe_settings'] : '';
// Sanitize efpe_settings if it exists and is an array
// if (isset($_POST['efpe_settings']) && is_array($_POST['efpe_settings'])) {
// 	$efpe_settings = array_map('sanitize_text_field', $_POST['efpe_settings']);
// }

// Sanitize other POST data
$event_per_page = isset($_POST['post_per_page']) ? absint(wp_unslash($_POST['post_per_page'])) : 0;
$efpe_event_limit = isset($_POST['efpe_post_limit']) ? absint(wp_unslash($_POST['efpe_post_limit'])) : 0;



if ($show_pagination && ! $efpe_query->is_main_query()) {
	// Paged argument.
	if (get_query_var('paged')) {
		$efpe_paged = get_query_var('paged');
	} elseif (get_query_var('page')) {
		$efpe_paged = get_query_var('page');
	} else {
		$efpe_paged = 1;
	}
	$load_more_text    = isset($efpe_settings['load_more_text']) ? $efpe_settings['load_more_text'] : $view_options['load_more_text'];
	$pagination_message = isset($efpe_settings['pagination_message']) ? $efpe_settings['pagination_message'] : $view_options['pagination_message'];
?>
	<span class="ta-efpe-pagination-data" data-loadmoretext="<?php echo esc_attr($load_more_text); ?>" data-endingtext="<?php echo esc_attr($pagination_message); ?>"></span>

	<nav class="efpe-post-pagination efpe-on-desktop <?php echo esc_attr($pagination_type); ?>">
		<?php
		EventfulForElementorLoopHtml::efpe_pagination_bar($efpe_query, $view_options, $layout_preset, $efpe_gl_id, $efpe_settings, $event_per_page, $efpe_event_limit);
		?>
	</nav>
<?php
}
?>