<?php

namespace ThemeAtelier\EventfulForElementor\Frontend\Helpers;


/**
 * The file of query insides.
 *
 * @package eventful-for-elementor
 * @subpackage eventful-for-elementor/src/Helpers
 *
 */

// If this file is called directly, abort.
if (!defined('WPINC')) {
	die;
}
/**
 * Event all html method.
 */
class EventfulForElementorLoopHtml
{
	/**
	 * Event title html.
	 *
	 * @param array  $sorter post content option array.
	 * @param string $layout layout preset.
	 * @return void
	 */
	public static function efpe_post_title($options, $efpe_settings, $post,  $is_table = false)
	{
		$show_post_title	= isset($efpe_settings['show_title']) ? $efpe_settings['show_title'] : $options['show_title'];
		$efpe_page_link_type     = isset($efpe_settings['efpe_page_link_type']) ? $efpe_settings['efpe_page_link_type'] : $options['efpe_page_link_type'];
		$efpe_link_rel     = isset($efpe_settings['efpe_link_rel']) ? $efpe_settings['efpe_link_rel'] : $options['efpe_link_rel'];
		$efpe_link_rel_text    = '1' === $efpe_link_rel ? "rel='nofollow'" : '';
		$efpe_link_target     = isset($efpe_settings['efpe_link_target']) ? $efpe_settings['efpe_link_target'] : $options['efpe_link_target'];
		$efpe_event_title = get_the_title($post->ID);

		if ($show_post_title && !empty($efpe_event_title)) {
			// Event Title Settings.
			$post_title_tag    = isset($options['title_tag']) ? $options['title_tag'] : 'h2';
			$limit_post_title = isset($options['title_limit']) ? $options['title_limit'] : "";
			if ($limit_post_title) {
				$post_title_length = isset($options['title_length']) ? $options['title_length'] : '';
				$efpe_event_title    = EventfulForElementorFunctions::limit_post_title($efpe_event_title, $post_title_length);
			}

			$allowed_html_tags = array(
				'em'     => array(),
				'strong' => array(),
				'sup'    => array(),
				'i'      => array(),
				'small'  => array(),
				'del'    => array(),
				'ins'    => array(),
				'span'   => array(
					'style' => array(),
					'class' => array(),
				),
			);
			$td                = self::table_td($is_table);
			$allow_tag         = array('td' => array());

			ob_start();
			echo wp_kses($td['start'], $allow_tag);
			include EventfulForElementorFunctions::eventful_for_elementor_locate_template('item/title.php');
			echo wp_kses($td['end'], $allow_tag);
			$title = apply_filters('efpe_item_title', ob_get_clean());
			echo wp_kses_post($title);
		}
	}

	/**
	 * Show Event Content html.
	 *
	 * @param array $sorter The field ID array.
	 * @param array $options options.
	 * @return void
	 */
	public static function efpe_content_html($options, $efpe_settings, $post, $is_table = false)
	{
		$show_content    = isset($efpe_settings['show_content']) ? $efpe_settings['show_content'] : $options['show_content'];
		$show_read_more       = isset($efpe_settings['show_read_more']) ? $efpe_settings['show_read_more'] : $options['show_read_more'];

		$td                  = self::table_td($is_table);
		$allow_tag           = array('td' => array());
		if ($show_content || $show_read_more) {
			ob_start();
			echo wp_kses($td['start'], $allow_tag);
			include EventfulForElementorFunctions::eventful_for_elementor_locate_template('item/content.php');
			echo wp_kses($td['end'], $allow_tag);
			$description = apply_filters('efpe_item_description', ob_get_clean());
			echo wp_kses_post($description);
		}
	}


	/**
	 * Read more function
	 *
	 * @param array $post The post.
	 * @param array $efpe_settings The efpe_settings.
	 */
	public static function efpe_readmore($options, $post, $efpe_settings)
	{
		$show_read_more 		= isset($efpe_settings['show_read_more']) ? $efpe_settings['show_read_more'] : $options['show_read_more'];
		$content_type 			= isset($efpe_settings['content_type']) ? $efpe_settings['content_type'] : $options['content_type'];
		$read_more_text 		= isset($efpe_settings['read_more_text']) ? $efpe_settings['read_more_text'] : $options['read_more_text'];
		$content_type 			= isset($efpe_settings['content_type']) ? $efpe_settings['content_type'] : $options['content_type'];
		$read_more_type     	= isset($efpe_settings['read_more_type']) ? $efpe_settings['read_more_type'] : $options['read_more_type'];
		$efpe_read_label     	= isset($efpe_settings['read_more_text']) ? $efpe_settings['read_more_text'] : $options['read_more_text'];
		$efpe_page_link_type    = isset($efpe_settings['efpe_page_link_type']) ? $efpe_settings['efpe_page_link_type'] : $options['efpe_page_link_type'];
		$efpe_link_rel     		= isset($efpe_settings['efpe_link_rel']) ? $efpe_settings['efpe_link_rel'] : $options['efpe_link_rel'];
		$efpe_link_rel_text    	= '1' === $efpe_link_rel ? "rel='nofollow'" : '';
		$efpe_link_target     	= isset($efpe_settings['efpe_link_target']) ? $efpe_settings['efpe_link_target'] : $options['efpe_link_target'];

		if (!$show_read_more || 'full_content' === $content_type) {
			return '';
		}

		ob_start();
		include EventfulForElementorFunctions::eventful_for_elementor_locate_template('item/read-more.php');
		$read_more_button = apply_filters('efpe_read_more_btn', ob_get_clean(), $link = get_permalink($post));
		echo wp_kses_post($read_more_button);
	}

	/**
	 * Event thumb HTML.
	 *
	 * @param array $sorter post content option array.
	 * @param int   $scode_id Shortcode ID.
	 * @param int   $slide_id The slide/post ID.
	 * @param array $options The slide/post ID.
	 * @return void
	 */
	public static function efpe_post_thumb_html($sorter, $post, $options, $efpe_settings, $layout, $is_table = false)
	{
		$show_image 	= isset($efpe_settings['show_image']) ? $efpe_settings['show_image'] : $options['show_image'];
		$post_thumb_meta 	= isset($efpe_settings['thumb_meta']) ? $efpe_settings['thumb_meta'] : $options['thumb_meta'];
		$taxonomy_name 	= isset($efpe_settings['thumb_meta_taxonomy']) ? $efpe_settings['thumb_meta_taxonomy'] : $options['thumb_meta_taxonomy'];
		$post_thumb_meta_position 	= isset($efpe_settings['thumb_meta_position']) ?  $efpe_settings['thumb_meta_position'] : $options['thumb_meta_position'];
		$meta_date_format     = isset($efpe_settings['thumb_meta_date_format']) ? $efpe_settings['thumb_meta_date_format'] : $options['thumb_meta_date_format'];
		$efpe_page_link_type     = isset($efpe_settings['efpe_page_link_type']) ? $efpe_settings['efpe_page_link_type'] : $options['efpe_page_link_type'];
		$efpe_link_rel     = isset($efpe_settings['efpe_link_rel']) ? $efpe_settings['efpe_link_rel'] : $options['efpe_link_rel'];
		$efpe_link_rel_text    = '1' === $efpe_link_rel ? "rel='nofollow'" : '';
		$efpe_link_target     = isset($efpe_settings['efpe_link_target']) ? $efpe_settings['efpe_link_target'] : $options['efpe_link_target'];

		if ($show_image) {
			$efpe_image_attr  = EventfulForElementorFunctions::efpe_sized_thumb($options, $post->ID, $efpe_settings);
			$thumb_url       = $efpe_image_attr['src'];
			$retina_img_src  = $efpe_image_attr['2x_src'];
			$retina_img_attr = '';
			if (!empty($retina_img_src)) {
				$retina_img_attr = 'srcset="' . esc_attr($thumb_url) . ', ' . esc_attr($retina_img_src) . ' 2x"';
			}

			$alter_text       = EventfulForElementorFunctions::efpe_thumb_alter_text($post->ID);

			$td               = self::table_td($is_table);
			$allow_tag        = array('td' => array());
			if (!empty($thumb_url)) {
				ob_start();
				echo wp_kses($td['start'], $allow_tag);
				include EventfulForElementorFunctions::eventful_for_elementor_locate_template('item/thumbnail.php');
				echo wp_kses($td['end'], $allow_tag);
				$item_thumb = apply_filters('efpe_item_thumbnail', ob_get_clean());
				echo wp_kses_post($item_thumb); // phpcs:ignore
			}
		}
	}

	/**
	 * Event fildes HTML
	 *
	 * @param array $sorter post content option array.
	 * @param int   $visitor_count views count.
	 * @return void
	 */
	public static function efpe_event_fildes_html($visitor_count, $post, $options, $efpe_settings, $scode_id, $is_table = false)
	{
		$show_event_meta   = isset($efpe_settings['show_event_meta']) ? $efpe_settings['show_event_meta'] : $options['show_event_meta'];
		if ($show_event_meta) {
			ob_start();
			include EventfulForElementorFunctions::eventful_for_elementor_locate_template('item/event-fildes.php');
			$item_meta = apply_filters('efpe_item_meta', ob_get_clean());
			echo wp_kses_post($item_meta);
		}
	}

	/**
	 * Event content with thumb.
	 *
	 * @param array  $sorter post sorting option.
	 * @param string $layout Layout preset.
	 * @param int    $visitor_count visitor number.
	 * @param int    $scode_id The Shortcode ID.
	 * @param object $post The Event object.
	 * @return void
	 */
	public static function efpe_post_content_with_thumb($sorter, $layout, $visitor_count, $scode_id, $post, $options, $efpe_settings, $is_table = false)
	{
		self::efpe_post_thumb_html($sorter, $post, $options, $efpe_settings, $layout, $is_table);
		self::efpe_post_title($options, $efpe_settings, $post, $is_table);
		self::efpe_event_fildes_html($visitor_count, $post, $options, $efpe_settings, $scode_id);
		self::efpe_content_html($options, $efpe_settings, $post);
	}

	/**
	 * Event content without thumb.
	 *
	 * @param array  $sorter post sorting option.
	 * @param string $layout Layout preset.
	 * @param int    $visitor_count visitor number.
	 * @param object $post visitor number.
	 * @param array  $options Shortcode options.
	 * @return void
	 */
	public static function efpe_post_content_without_thumb($sorter, $layout, $visitor_count, $scode_id, $post, $options, $efpe_settings, $is_table = false)
	{
		self::efpe_post_title($options, $efpe_settings, $post, $is_table);
		self::efpe_event_fildes_html($visitor_count, $post, $options, $efpe_settings, $scode_id);
		self::efpe_content_html($options, $efpe_settings, $post);
	}

	/**
	 * HTML classes for Event.
	 *
	 * @return string
	 */
	public static function efpe_alt_post_class($layout_preset, $content_orientation, $options, $efpe_settings)
	{
		$post_list_orientation = isset($efpe_settings['post_list_orientation']) ? $efpe_settings['post_list_orientation'] : $options['post_list_orientation'];
		if ('carousel_layout' === $layout_preset || 'grid_layout' === $layout_preset) {
			if ('overlay' === $content_orientation) {
				$efpe_alt_post_class = ' ta-overlay eventful__item';
			} else {
				$efpe_alt_post_class = 'eventful__item ';
			}
		} else {
			$efpe_alt_post_class = ' eventful__item';
		}
		return apply_filters('efpe_post_class_name', $efpe_alt_post_class);
	}

	/**
	 * Pagination function
	 *
	 * @param object $loop Query array.
	 * @param array  $view_options options.
	 * @param array  $layout layout.
	 * @param array  $views_id id.
	 * @param array  $paged paged.
	 * @param array  $on_screen screen type.
	 */
	public static function efpe_pagination_bar($loop, $view_options, $layout, $views_id, $efpe_settings, $event_per_page, $efpe_event_limit, $on_screen = null)
	{
		$posts_found   = $loop->found_posts;
		$event_offset   = isset($efpe_settings['efpe_post_offset']) ? $efpe_settings['efpe_post_offset'] : $view_options['efpe_post_offset'];
		$posts_found   = (int) $posts_found - (int) $event_offset;
		$event_limit    = !empty($efpe_event_limit) ? $efpe_event_limit : $view_options['efpe_post_limit'];
		$event_limit    = ($event_limit > 0 && $posts_found > $event_limit) ? $event_limit : $posts_found;
		$view_post_per_page = isset($view_options['post_per_page']) ? $view_options['post_per_page'] : '-1';
		$event_per_page = !empty($event_per_page) ? $event_per_page : $view_post_per_page;
		$event_per_page = ($event_per_page > $event_limit) ? $event_limit : $event_per_page;

		$layout_preset = isset($layout['efpe_layout_preset']) ? $layout['efpe_layout_preset'] : '';
		// Event display settings.
		if ('filter_layout' === $layout_preset) {
			$pagination_type = isset($view_options['filter_pagination_type']) ? $view_options['filter_pagination_type'] : '';
		} else {
			$pagination_type = isset($view_options['post_pagination_type']) ? $view_options['post_pagination_type'] : 'ajax_load_more';
			if ('on_mobile' === $on_screen) {
				$pagination_type = isset($view_options['post_pagination_type_mobile']) ? $view_options['post_pagination_type_mobile'] : 'infinite_scroll';
			}
		}
		$event_limit = (int) $event_limit;
		if ($event_limit < 1) {
			$pages = 0;
		} else {
			$pages = EventfulForElementorFunctions::efpe_max_pages($event_limit, $event_per_page);
		}
		$big = 999999999; // need an unlikely integer.
		if ($pages > 1) {
			$page_current     = max(1, get_query_var('paged'));
			$filter_url_value = isset($_SERVER['QUERY_STRING']) ? sanitize_text_field(wp_unslash($_SERVER['QUERY_STRING'])) : '';
			if (!empty($filter_url_value)) {
				$shortcode_id = isset($_GET['sps']) ? sanitize_text_field(wp_unslash($_GET['sps'])) : '';
				if ($shortcode_id == $views_id) {
					$efpe_page = isset($_GET['efpe_page']) ? sanitize_text_field(wp_unslash($_GET['efpe_page'])) : '';
					if (!empty($efpe_page)) {
						$page_current = $efpe_page;
					}
				}
			}

			if ('ajax_pagination' === $pagination_type) {
				$page_links = paginate_links(
					array(
						'base'      => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
						'format'    => '?paged=%#%',
						'current'   => $page_current,
						'total'     => $pages,
						'show_all'  => true,
						'prev_next' => false,
						'type'      => 'array',
						'prev_text' => '<i class="elementor-icons-manager__tab__item__icon fas fa-angle-left"></i>',
						'next_text' => '<i class="elementor-icons-manager__tab__item__icon fas fa-angle-right"></i>',
					)
				);
				$prev_link  = '<a class="next page-numbers" href="#"><i class="elementor-icons-manager__tab__item__icon fas fa-angle-right"></i></a>';
				$next_link  = '<a class="prev page-numbers active" href="#"><i class="elementor-icons-manager__tab__item__icon fas fa-angle-left"></i></a>';
				array_unshift($page_links, $next_link);
				$page_links[] = $prev_link;
				$html         = '';
				$p_num        = 0;
				foreach ($page_links as $link) {
					$class = 'page-numbers ';
					if (strpos($link, 'current') !== false) {
						$class .= 'active';
					}
					if (strpos($link, 'next') !== false) {
						$data_page = 'data-page="next"';
						$class    .= 'efpe_next ';
					} elseif (strpos($link, 'prev') !== false) {
						$data_page = 'data-page="prev"';
						$class    .= 'efpe_prev';
					} else {
						$data_page = 'data-page="' . $p_num . '"';
					}
					$link  = preg_replace('/<span[^>]*>/', '<a href="#" class="' . $class . '" ' . $data_page . '>', $link);
					$link  = preg_replace('/<a [^>]*>/', '<a href="#" class="' . $class . '" ' . $data_page . '>', $link);
					$link  = str_replace('</span>', '</a>', $link);
					$html .= $link;
					$p_num++;
				}
				echo wp_kses_post($html);
			} elseif ('no_ajax' === $pagination_type) {

				$paged_var    = 'paged' . $views_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'  => apply_filters('efpe_show_all_normal_pagination', true),
						'prev_next' => true,
						'end_size'  => 2,
						'mid_size'  => 1,
						'type'      => 'array',
						'prev_text' => '<i class="elementor-icons-manager__tab__item__icon fas fa-angle-left"></i>',
						'next_text' => '<i class="elementor-icons-manager__tab__item__icon fas fa-angle-right"></i>',
					)
				);
				$allowed_html = array(
					'nav' => array(
						'class' => array(),
					),
					'a' => array(
						'class' => array(),
						'href' => array(),
						'aria-current' => array(),
					),
					'span' => array(
						'class' => array(),
						'aria-current' => array(),
					),
					'i' => array(
						'class' => array(),
					),
				);
				echo wp_kses(implode($page_links), $allowed_html);
			} else {
				$page_links = paginate_links(
					array(
						'base'      => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
						'format'    => '?paged=%#%',
						'current'   => $page_current,
						'total'     => $pages,
						'show_all'  => true,
						'prev_next' => false,
						'type'      => 'array',
						'prev_text' => '<i class="elementor-icons-manager__tab__item__icon fas fa-angle-left"></i>',
						'next_text' => '<i class="elementor-icons-manager__tab__item__icon fas fa-angle-right"></i>',
					)
				);
				$html       = '';
				$p_num      = 1;
				foreach ($page_links as $link) {
					$class = 'page-numbers ';
					if (strpos($link, 'current') !== false) {
						$class .= 'active';
					}
					if (strpos($link, 'next') !== false) {
						$data_page = 'data-page="next"';
						$class    .= 'efpe_next ';
					} elseif (strpos($link, 'prev') !== false) {
						$data_page = 'data-page="prev"';
						$class    .= 'efpe_prev active';
					} else {
						$data_page = 'data-page="' . $p_num . '"';
					}
					$link  = preg_replace('/<span[^>]*>/', '<a href="#" class="' . $class . '" ' . $data_page . '>', $link);
					$link  = preg_replace('/<a [^>]*>/', '<a href="#" class="' . $class . '" ' . $data_page . '>', $link);
					$link  = str_replace('</span>', '</a>', $link);
					$html .= $link;
					$p_num++;
				}
				echo wp_kses_post($html);
			}
		}
	}

	/**
	 * Section title
	 *
	 * @param int $efpe_id Shortcode id.
	 * @return void
	 */

	public static function efpe_section_title($section_title_text, $show_section_title)
	{

		if ($show_section_title) {
			$section_title_text = apply_filters('efpe_section_title_text', $section_title_text);
			ob_start();
			do_action('efpe_before_section_title');
			include EventfulForElementorFunctions::eventful_for_elementor_locate_template('section-title.php');
			do_action('efpe_after_section_title');
			$section_title = apply_filters('efpe_filter_section_title', ob_get_clean());
			echo wp_kses_post($section_title);
		}
	}

	/**
	 * Preloader
	 *
	 * @param bool $preloader show preloader.
	 * @return void
	 */
	public static function efpe_preloader($preloader)
	{
		if ($preloader && !is_admin()) {
			ob_start();
			include EventfulForElementorFunctions::eventful_for_elementor_locate_template('preloader.php');
			$preloader = apply_filters('efpe_preloader', ob_get_clean());
			echo wp_kses_post($preloader);
		}
	}

	/**
	 * Get all query posts.
	 *
	 * @param array $options Views options.
	 * @param array $layout Layout preset.
	 * @param array $sorter  Event sorting options.
	 * @param object $efpe_query post query.
	 * @param int   $view_id Shortcode ID.
	 * @return void
	 */
	public static function eventful_for_elementor_get_posts($options, $layout_preset, $sorter, $efpe_query, $view_id, $efpe_settings)
	{
		$efpe_count = 1;
		$all_posts = $efpe_query->posts;
		foreach ($all_posts as $key => $post) {
			$visitor_count = get_post_meta($post->ID, '_post_views_count', true);
			self::efpe_post_loop($options, $layout_preset, $sorter, $efpe_count, $view_id, $post, $efpe_settings);
			$efpe_count++;
		}
	}

	/**
	 * Table td markup.
	 *
	 * @param  mixed $is_table check table layout.
	 * @return array
	 */
	public static function table_td($is_table = false)
	{
		$td_before = '';
		$td_after  = '';
		if ($is_table) {
			$td_before = '<td>';
			$td_after  = '</td>';
		}
		return array(
			'start' => $td_before,
			'end'   => $td_after,
		);
	}

	/**
	 * Event Loop.
	 *
	 * @param array  $options Views options.
	 * @param string $layout Layout preset.
	 * @param array  $sorter Event sorting options.
	 * @param int    $scode_id Shortcode ID.
	 * @return void
	 */
	public static function efpe_post_loop($options, $layout_preset, $sorter, $efpe_count, $scode_id, $post, $efpe_settings)
	{
		$thumb_zoom 			= isset($efpe_settings['thumb_zoom']) ? $efpe_settings['thumb_zoom'] : $options['thumb_zoom'];
		$thumb_gray_scale 		= isset($efpe_settings['thumb_gray_scale']) ? $efpe_settings['thumb_gray_scale'] : $options['thumb_gray_scale'];
		$content_orientation 	= isset($efpe_settings['content_orientation']) ? $efpe_settings['content_orientation'] : $options['content_orientation'];
		$visitor_count     		= get_post_meta($post->ID, '_post_views_count', true);
		if (('carousel_layout' === $layout_preset || 'grid_layout' === $layout_preset) && 'default' === $content_orientation) {
?>
			<div class="eventful__item <?php echo esc_attr($thumb_gray_scale); ?> <?php echo esc_attr($thumb_zoom); ?> <?php if ($layout_preset == 'carousel_layout') : ?> swiper-slide swiper-lazy <?php endif; ?>">

				<div class="efpe-post efp-item-<?php echo esc_attr($post->ID); ?>" data-id="<?php echo esc_attr($post->ID); ?>">

					<?php
					self::efpe_post_content_with_thumb($sorter, $layout_preset, $visitor_count, $scode_id, $post, $options, $efpe_settings);
					?>
				</div>
			</div>
		<?php
		} else {
			$animation_class = '';
			if (('overlay' === $content_orientation || 'overlay-box' === $content_orientation)) {
				$animation_class = ('on_hover' === EventfulForElementorFunctions::efpe_metabox_value('post_overlay_content_visibility', $options)) ? EventfulForElementorFunctions::efpe_metabox_value('post_animation', $options) . ' animated' : '';
			}
		?>
			<div class="<?php if ($layout_preset == 'carousel_layout') : ?> swiper-slide swiper-lazy swiper-lazy-loaded <?php endif; ?>">

				<div class="<?php echo esc_attr(self::efpe_alt_post_class($layout_preset, $content_orientation, $options, $efpe_settings)); ?> <?php echo esc_attr($thumb_zoom); ?> <?php echo esc_attr($thumb_gray_scale); ?> efpe-item-<?php echo esc_attr($post->ID); ?>" data-id="<?php echo esc_attr($post->ID); ?>">
					<div class="efpe-post">
						<?php
						self::efpe_post_thumb_html($sorter, $post, $options, $efpe_settings, $layout_preset);
						?>
						<div class="eventful__item__details <?php echo esc_html($animation_class); ?>">
							<?php
							self::efpe_post_content_without_thumb($sorter, $layout_preset, $visitor_count, $scode_id, $post, $options, $efpe_settings);
							?>
						</div>
					</div>
				</div>
			</div>
<?php
		}
	}

	/**
	 * PCP shortcode markup wrapper classes.
	 *
	 * @param string $layout_preset The selected layout name.
	 * @param int    $shortcode_id The shortcode ID.
	 *
	 */
	public static function efpe_wrapper_classes($layout_preset, $shortcode_id, $grid_style = null, $item_same_height_class = '')
	{
		$wrapper_class = "efpe-section ta-container efpe-wrapper-{$shortcode_id}";
		switch ($layout_preset) {
			case 'carousel_layout':
				$wrapper_class .= " efpe-carousel-wrapper{$item_same_height_class}";
				break;
			case 'grid_layout':
				$wrapper_class .= 'even' === $grid_style ? ' efpe-even' : ' efpe-masonry';
				$wrapper_class .= $item_same_height_class;
				break;
		}

		echo esc_attr($wrapper_class);
	}

	/**
	 * Shortcode Wrapper data attributes.
	 *
	 * @param int    $shortcode_id The shortcode ID.
	 * @return void
	 */
	public static function wrapper_data($pagination_type, $pagination_type_mobile, $shortcode_id, $options, $layout_preset)
	{
		$settings_args = [];
		$wrapper_data = '';
		if ($pagination_type) {
			$wrapper_data .= " data-pagination={$pagination_type}";
		}
		if ($pagination_type_mobile) {
			$wrapper_data .= " data-pagination_mobile={$pagination_type_mobile}";
		}
		if ($shortcode_id) {
			$wrapper_data .= " data-sid={$shortcode_id}";
		}
		if ('carousel_layout' != $layout_preset) {
			if ($options['post_per_page']) {
				$wrapper_data .= " data-post_per_page={$options['post_per_page']}";
			}
		}
		if ($options['efpe_post_limit']) {
			$wrapper_data .= " data-efpe_post_limit={$options['efpe_post_limit']}";
		}

		$settings_args['layout_preset'] = $layout_preset;
		$settings_args['post_list_orientation'] = isset($options['post_list_orientation']) ? $options['post_list_orientation'] : "";
		$settings_args['efpe_post_offset'] = isset($options['efpe_post_offset']) ? $options['efpe_post_offset'] : '';
		$settings_args['efpe_exclude_post_set'] = isset($options['efpe_exclude_post_set']) ? $options['efpe_exclude_post_set'] : array();
		$settings_args['efpe_exclude_too'] = isset($options['efpe_exclude_too']) ? $options['efpe_exclude_too'] : '';
		$settings_args['efpe_event_type'] = isset($options['efpe_event_type']) ? $options['efpe_event_type'] : '';
		$settings_args['content_orientation'] = isset($options['content_orientation']) ? $options['content_orientation'] : '';
		$settings_args['show_title'] = isset($options['show_title']) ? $options['show_title'] : '';
		$settings_args['show_image'] = isset($options['show_image']) ? $options['show_image'] : '';
		$settings_args['post_thumbnail_size'] = isset($options['post_thumbnail_size']) ? $options['post_thumbnail_size'] : '';
		$settings_args['post_thumbnail_custom_dimension'] = isset($options['post_thumbnail_custom_dimension']) ? $options['post_thumbnail_custom_dimension'] : '';
		$settings_args['thumb_meta'] = isset($options['thumb_meta']) ? $options['thumb_meta'] : '';
		$settings_args['thumb_meta_taxonomy'] = isset($options['thumb_meta_taxonomy']) ? $options['thumb_meta_taxonomy'] : '';
		$settings_args['thumb_meta_date_format'] = isset($options['thumb_meta_date_format']) ? $options['thumb_meta_date_format'] : '';
		$settings_args['efpe_page_link_type'] = isset($options['efpe_page_link_type']) ? $options['efpe_page_link_type'] : '';
		$settings_args['efpe_link_target'] = isset($options['efpe_link_target']) ? $options['efpe_link_target'] : '';
		$settings_args['efpe_link_rel'] = isset($options['efpe_link_rel']) ? $options['efpe_link_rel'] : '';
		$settings_args['custom_date_format'] = isset($options['custom_date_format']) ? $options['custom_date_format'] : '';
		$settings_args['thumb_meta_position'] = isset($options['thumb_meta_position']) ? $options['thumb_meta_position'] : '';
		$settings_args['thumb_lazy_load'] = isset($options['thumb_lazy_load']) ? $options['thumb_lazy_load'] : '';
		$settings_args['load_2x_image'] = isset($options['load_2x_image']) ? $options['load_2x_image'] : '';
		$settings_args['thumb_src_replace'] = isset($options['thumb_src_replace']) ? $options['thumb_src_replace'] : '';
		$settings_args['thumb_zoom'] = isset($options['thumb_zoom']) ? $options['thumb_zoom'] : '';
		$settings_args['thumb_gray_scale'] = isset($options['thumb_gray_scale']) ? $options['thumb_gray_scale'] : '';
		$settings_args['show_content'] = isset($options['show_content']) ? $options['show_content'] : '';
		$settings_args['content_type'] = isset($options['content_type']) ? $options['content_type'] : '';
		$settings_args['content_length_type'] = isset($options['content_length_type']) ? $options['content_length_type'] : '';
		$settings_args['content_limit'] = isset($options['content_limit']) ? $options['content_limit'] : '';
		$settings_args['content_characters_limit'] = isset($options['content_characters_limit']) ? $options['content_characters_limit'] : '';
		$settings_args['strip_tags'] = isset($options['strip_tags']) ? $options['strip_tags'] : '';
		$settings_args['allow_tag_name'] = isset($options['allow_tag_name']) ? $options['allow_tag_name'] : '';
		$settings_args['content_ellipsis'] = isset($options['content_ellipsis']) ? $options['content_ellipsis'] : '';
		$settings_args['show_read_more'] = isset($options['show_read_more']) ? $options['show_read_more'] : '';
		$settings_args['read_more_type'] = isset($options['read_more_type']) ? $options['read_more_type'] : '';
		$settings_args['read_more_text'] = isset($options['read_more_text']) ? $options['read_more_text'] : '';
		$settings_args['content_alignment'] = isset($options['content_alignment']) ? $options['content_alignment'] : '';
		$settings_args['show_meta'] = isset($options['show_meta']) ? $options['show_meta'] : '';
		$settings_args['meta_data'] = isset($options['meta_data']) ? $options['meta_data'] : '';
		$settings_args['select_author'] = isset($options['select_author']) ? $options['select_author'] : '';
		$settings_args['author_live_filters'] = isset($options['author_live_filters']) ? $options['author_live_filters'] : '';
		$settings_args['author_filter_style'] = isset($options['author_filter_style']) ? $options['author_filter_style'] : '';
		$settings_args['author_filter_label'] = isset($options['author_filter_label']) ? $options['author_filter_label'] : '';
		$settings_args['author_rename_all_text'] = isset($options['author_rename_all_text']) ? $options['author_rename_all_text'] : '';
		$settings_args['author_hide_empty'] = isset($options['author_hide_empty']) ? $options['author_hide_empty'] : '';
		$settings_args['author_show_count'] = isset($options['author_show_count']) ? $options['author_show_count'] : '';
		$settings_args['author_live_filter_align'] = isset($options['author_live_filter_align']) ? $options['author_live_filter_align'] : '';
		$settings_args['select_not_author'] = isset($options['select_not_author']) ? $options['select_not_author'] : '';
		$settings_args['author_icon'] = isset($options['author_icon']) ? $options['author_icon'] : '';
		$settings_args['meta_author_avatar'] = isset($options['meta_author_avatar']) ? $options['meta_author_avatar'] : '';
		$settings_args['select_sortby'] = isset($options['select_sortby']) ? $options['select_sortby'] : '';
		$settings_args['select_filter_order'] = isset($options['select_filter_order']) ? $options['select_filter_order'] : '';
		$settings_args['add_order_filter_post'] = isset($options['add_order_filter_post']) ? $options['add_order_filter_post'] : '';
		$settings_args['order_filter_options'] = isset($options['order_filter_options']) ? $options['order_filter_options'] : '';
		$settings_args['order_filter_label'] = isset($options['order_filter_label']) ? $options['order_filter_label'] : '';
		$settings_args['efpe_live_filter_align'] = isset($options['efpe_live_filter_align']) ? $options['efpe_live_filter_align'] : '';
		$settings_args['sortby_live_filters'] = isset($options['sortby_live_filters']) ? $options['sortby_live_filters'] : '';
		$settings_args['sortby_filter_style'] = isset($options['sortby_filter_style']) ? $options['sortby_filter_style'] : '';
		$settings_args['efpe_add_filter_orderby'] = isset($options['efpe_add_filter_orderby']) ? $options['efpe_add_filter_orderby'] : '';
		$settings_args['sortby_filter_label'] = isset($options['sortby_filter_label']) ? $options['sortby_filter_label'] : '';
		$settings_args['sortby_live_filter_align'] = isset($options['sortby_live_filter_align']) ? $options['sortby_live_filter_align'] : '';
		$settings_args['select_status'] = isset($options['select_status']) ? $options['select_status'] : '';
		$settings_args['select_date'] = isset($options['select_date']) ? $options['select_date'] : '';
		$settings_args['select_post_specific_date'] = isset($options['select_post_specific_date']) ? $options['select_post_specific_date'] : '';
		$settings_args['select_post_date_from'] = isset($options['select_post_date_from']) ? $options['select_post_date_from'] : '';
		$settings_args['select_post_date_to'] = isset($options['select_post_date_to']) ? $options['select_post_date_to'] : '';
		$settings_args['select_specific_month'] = isset($options['select_specific_month']) ? $options['select_specific_month'] : '';
		$settings_args['select_post_specific_year'] = isset($options['select_post_specific_year']) ? $options['select_post_specific_year'] : '';
		$settings_args['efpe_set_post_keyword'] = isset($options['efpe_set_post_keyword']) ? $options['efpe_set_post_keyword'] : '';
		$settings_args['add_search_filter_post'] = isset($options['add_search_filter_post']) ? $options['add_search_filter_post'] : '';
		$settings_args['keyword_filter_label'] = isset($options['keyword_filter_label']) ? $options['keyword_filter_label'] : '';
		$settings_args['keyword_live_filter_align'] = isset($options['keyword_live_filter_align']) ? $options['keyword_live_filter_align'] : '';
		$settings_args['meta_separator'] = isset($options['meta_separator']) ? $options['meta_separator'] : '';
		$settings_args['meta_date_format'] = isset($options['meta_date_format']) ? $options['meta_date_format'] : '';
		$settings_args['meta_custom_date_format'] = isset($options['meta_custom_date_format']) ? $options['meta_custom_date_format'] : '';
		$settings_args['date_icon'] = isset($options['date_icon']) ? $options['date_icon'] : '';
		$settings_args['meta_categories'] = isset($options['meta_categories']) ? $options['meta_categories'] : '';
		$settings_args['categories_icon'] = isset($options['categories_icon']) ? $options['categories_icon'] : '';
		$settings_args['comments_icon'] = isset($options['comments_icon']) ? $options['comments_icon'] : '';
		$settings_args['word_per_minute'] = isset($options['word_per_minute']) ? $options['word_per_minute'] : '';
		$settings_args['reading_time_postfix'] = isset($options['reading_time_postfix']) ? $options['reading_time_postfix'] : '';
		$settings_args['reading_time_icon'] = isset($options['reading_time_icon']) ? $options['reading_time_icon'] : '';
		$settings_args['efpe_advanced_filter'] = isset($options['efpe_advanced_filter']) ? $options['efpe_advanced_filter'] : '';
		$settings_args['efpe_add_filter_orderby'] = isset($options['efpe_add_filter_orderby']) ? $options['efpe_add_filter_orderby'] : '';
		$settings_args['taxonomy_options'] = isset($options['taxonomy_options']) ? $options['taxonomy_options'] : '';
		$settings_args['taxonomy_relation'] = isset($options['taxonomy_relation']) ? $options['taxonomy_relation'] : '';
		if ('carousel_layout' != $layout_preset) {
			$settings_args['show_post_pagination'] = isset($options['show_post_pagination']) ? $options['show_post_pagination'] : '';
			$settings_args['post_pagination_type'] = isset($options['post_pagination_type']) ? $options['post_pagination_type'] : '';
		}
		$settings_args['show_event_meta'] = isset($options['show_event_meta']) ? $options['show_event_meta'] : '';
		$settings_args['event_meta_data'] = isset($options['event_meta_data']) ? $options['event_meta_data'] : '';
		$settings_args['venue_settings'] = isset($options['venue_settings']) ? $options['venue_settings'] : '';
		$settings_args['venue_map_link'] = isset($options['venue_map_link']) ? $options['venue_map_link'] : '';
		$settings_args['event_venue_icon'] = isset($options['event_venue_icon']) ? $options['event_venue_icon'] : '';
		$settings_args['event_organizer_icon'] = isset($options['event_organizer_icon']) ? $options['event_organizer_icon'] : '';
		$settings_args['event_price_icon'] = isset($options['event_price_icon']) ? $options['event_price_icon'] : '';
		$settings_args['event_date_icon'] = isset($options['event_date_icon']) ? $options['event_date_icon'] : '';
		$settings_args['event_fildes_date_type'] = isset($options['event_fildes_date_type']) ? $options['event_fildes_date_type'] : '';
		$settings_args['event_fildes_date_format'] = isset($options['event_fildes_date_format']) ? $options['event_fildes_date_format'] : '';
		$settings_args['efpe_custom_event_date_format'] = isset($options['efpe_custom_event_date_format']) ? $options['efpe_custom_event_date_format'] : '';
		$settings_args['event_meta_separator'] = isset($options['event_meta_separator']) ? $options['event_meta_separator'] : '';
		$wrapper_data .= ' data-efpe_settings="' . esc_attr(wp_json_encode($settings_args)) . '"';

		echo wp_kses_post($wrapper_data);
	}

	/**
	 * Full html show.
	 *
	 * @param array  $view_options all options.
	 * @param array  $layout show layout.
	 * @param array  $efpe_gl_id Shortcode ID.
	 * @param array  $section_title section title.
	 * @param object $query layout query.
	 */
	public static function efpe_html_show($view_options, $layout_preset, $efpe_gl_id, $query = array())
	{
		$options              	= $view_options;
		if (isset($_POST['nonce']) && !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ta_efpe_nonce')) {
			wp_die("Invalid nonce");
		}
		$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']);
		// }
		$view_post_per_page 	= isset($view_options['post_per_page']) ? $view_options['post_per_page'] : '-1';
		$event_per_page          = isset($_POST['post_per_page']) ? sanitize_text_field(wp_unslash($_POST['post_per_page'])) : $view_post_per_page;
		$efpe_event_limit        = isset($_POST['efpe_post_limit']) ? sanitize_text_field(wp_unslash($_POST['efpe_post_limit'])) : $view_options['efpe_post_limit'];
		$grid_style           	= isset($view_options['efpe_grid_style']) ? $view_options['efpe_grid_style'] : 'even';
		$event_content_sorter  	= isset($view_options['post_content_sorter']) ? $view_options['post_content_sorter'] : '';
		$efpe_content_position 	= isset($view_options['post_content_orientation']) ? $view_options['post_content_orientation'] : '';
		$carousel_style_columns_margin  	= isset($view_options['carousel_style_columns_margin']) ? $view_options['carousel_style_columns_margin'] : '';
		$margin_between_post  	= !empty($carousel_style_columns_margin['size']) ? $carousel_style_columns_margin['size'] : 15;
		$show_preloader       	= !empty($view_options['show_preloader']) ? $view_options['show_preloader'] : 0;
		$item_same_height_class = !empty($view_options['item_same_height']) ? ' efpe_same_height ' : '';

		if (is_object($query) && !empty($query)) {
			$query_args       = array();
			$efpe_query        = $query;
			$total_post_count = $efpe_query->post_count;
		} else {
			$query_args       = EventfulForElementorQueryinside::get_filtered_content($view_options, $efpe_gl_id, $layout_preset, $event_per_page, $efpe_event_limit, $efpe_settings);
			$efpe_query        = new \WP_Query($query_args);
			$total_post_count = $efpe_query->post_count;
		}
		// Pagination.
		$show_pagination = isset($view_options['show_post_pagination']) ? $view_options['show_post_pagination'] : true;
		if ('filter_layout' === $layout_preset) {
			$pagination_type        = isset($view_options['filter_pagination_type']) ? $view_options['filter_pagination_type'] : '';
			$pagination_type_mobile = isset($view_options['filter_pagination_type']) ? $view_options['filter_pagination_type'] : '';
		} else {
			$pagination_type        = isset($view_options['post_pagination_type']) ? $view_options['post_pagination_type'] : 'ajax_load_more';
			$pagination_type_mobile = isset($view_options['post_pagination_type_mobile']) ? $view_options['post_pagination_type_mobile'] : 'infinite_scroll';
		}
		$accordion_mode  = isset($view_options['accordion_mode']) ? $view_options['accordion_mode'] : '';
		$advanced_filter = isset($view_options['efpe_advanced_filter']) ? $view_options['efpe_advanced_filter'] : false;

		$spsp_lang = '';
		if (function_exists('pll_current_language')) {
			$spsp_lang = pll_current_language();
		}

		if ('carousel_layout' === $layout_preset) {
			include EventfulForElementorFunctions::eventful_for_elementor_locate_template('carousel.php');
		} elseif ('grid_layout' === $layout_preset) {
			include EventfulForElementorFunctions::eventful_for_elementor_locate_template('grid.php');
		}
	}
}
