<?php

namespace ThemeAtelier\EventfulForElementor\Frontend\Helpers;

if (! defined('ABSPATH')) exit; // Exit if accessed directly

use ThemeAtelier\EventfulForElementor\Frontend\Helpers\EventfulForElementorQueryinside;

/**
 * The file of live filter.
 *
 * @package eventful-for-elementor
 * @subpackage eventful-for-elementor/src/Helpers
 *
 * @since 2.0.0
 */

/**
 * Live filter helper method.
 *
 * @since 2.0.0
 */
class EventfulForElementorLiveFilter
{
	/**
	 * Initialize the class and set its properties.
	 *
	 * @since    2.0.0
	 */
	public function __construct()
	{
		add_action('wp_ajax_efpe_live_filter_reset', array($this, 'efpe_live_filter_reset'));
		add_action('wp_ajax_efpe_admin_live_filter_reset', array($this, 'efpe_admin_live_filter_reset'));
		add_action('wp_ajax_nopriv_efpe_live_filter_reset', array($this, 'efpe_live_filter_reset'));
	}
	/**
	 * Live filter markup style.
	 *
	 * @param string $btn_type Filter type.
	 * @param string $taxonomy Current taxonomy to view.
	 * @param string $label filter label.
	 * @param string $all_text all text.
	 * @param string $align alignment.
	 * @param bool   $show_count show hide post count.
	 * @param int    $term term id.
	 * @param string $name term name.
	 * @param int    $p_count term found post.
	 * @param int    $id   post id.
	 * @param string $pre_selected selected.
	 * @param string $pre_checked  checked.
	 * @return array
	 */
	public static function efpe_filter_style($btn_type, $taxonomy, $label, $all_text, $align = 'center', $show_count = false, $term = null, $name = null, $p_count = null, $id = '', $pre_selected = '', $pre_checked = '')
	{
		if ($show_count) {
			$post_count_markup = '<span class="efpe-count">(' . $p_count . ')</span>';
		} else {
			$post_count_markup = '';
		}
		$is_checked       = $pre_checked;
		$is_selected      = $pre_selected;
		$checked          = $pre_checked;
		$selected         = $pre_selected;
		$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 == $id) {
				$filter_url_value = isset($_GET["tx_$taxonomy"]) ? sanitize_text_field(wp_unslash($_GET["tx_$taxonomy"])) : '';
				if (!empty($filter_url_value)) {
					if (strpos($filter_url_value, ',') !== false) {
						$filter_url_value = explode(',', $filter_url_value);
					}
					if (is_array($filter_url_value)) {
						if (in_array($term, $filter_url_value)) {
							$is_checked  = 'checked';
							$is_selected = 'selected';
						} else {
							$is_checked  = $pre_checked;
							$is_selected = $pre_selected;
						}
					} else {
						if ($filter_url_value == $term) {
							$is_checked  = 'checked';
							$is_selected = 'selected';
						} else {
							$is_checked  = $pre_checked;
							$is_selected = $pre_selected;
						}
					}
				}
			}
		}

		$checked  = $pre_checked;
		$selected = $pre_selected;

		if ('fl_checkbox' === $btn_type) {
			$all_label  = !empty($all_text) ? $all_text : '';
			$all_button = !empty($all_text) ? '<div class="fl_checkbox"><label><input checked type="checkbox" name="' . $taxonomy . '" data-taxonomy="' . $taxonomy . '"value="all">' . $all_label . '</label></div>' : '';

			$first_item = '<form class="efpe-filter-by-checkbox efpe-bar" data-taxonomy="' . $taxonomy . '" style="text-align:' . esc_attr($align) . ';"> <p>' . esc_html($label) . '</p>';
			$push_item  = '<div class="fl_checkbox"><label><input ' . $is_checked . ' name="' . $taxonomy . '" type="checkbox" ' . $checked . ' data-taxonomy="' . $taxonomy . '" value="' . $term . '">' . $name . $post_count_markup . '</span></label></div>';
		} elseif ('fl_radio' === $btn_type) {
			$all_label  = !empty($all_text) ? $all_text : '';
			$all_button = !empty($all_text) ? '<div class="fl_radio"><label><input checked type="radio" name="' . $taxonomy . '" data-taxonomy="' . $taxonomy . '"value="all">' . $all_label . '</label></div>' : '';
			$first_item = '<form class="efpe-filter-by efpe-bar" style="text-align:' . esc_attr($align) . ';"> <p>' . esc_html($label) . '</p>' . $all_button;
			$push_item  = '<div class="fl_radio"><label><input ' . $is_checked . ' name="' . $taxonomy . '" type="radio" ' . $checked . ' data-taxonomy="' . $taxonomy . '" value="' . $term . '">' . $name . $post_count_markup . '</span></label></div>';
		} elseif ('fl_btn' === $btn_type) {
			$all_label  = !empty($all_text) ? '<div>' . $all_text . '</div>' : '';
			$all_button = !empty($all_text) ? '<div class="fl_radio"><label><input checked type="radio" name="' . $taxonomy . '" data-taxonomy="' . $taxonomy . '" value="all">' . $all_label . '</label></div>' : '';

			$first_item = '<form class="efpe-filter-by efpe-bar fl_button filter-' . $taxonomy . '" style="text-align:' . esc_attr($align) . ';"> <p>' . esc_html($label) . '</p>' . $all_button;
			$push_item  = '<div class="fl_radio"><label><input ' . $is_checked . ' name="' . $taxonomy . '" type="radio" ' . $checked . ' data-taxonomy="' . $taxonomy . '" value="' . $term . '"><div>' . $name . $post_count_markup . '</div></label></div>';
		} else {
			$all_label  = !empty($all_text) ? $all_text : '';
			$all_button = !empty($all_text) ? '<option value="all"  data-taxonomy="' . $taxonomy . '">' . $all_label . '</option>' : '';

			$first_item = '<form class="efpe-filter-by efpe-bar" style="text-align:' . esc_attr($align) . ';"> <label class="efpe-label">' . esc_html($label) . '</label> <select>' . $all_button;
			$push_item  = '<option data-taxonomy="' . $taxonomy . '" ' . $selected . ' ' . $is_selected . ' value="' . $term . '">' . $name . $post_count_markup . '</option>';
		}
		$filter_output = array(
			'first_item' => $first_item,
			'push_item'  => $push_item,
		);
		return $filter_output;
	}
	/**
	 * Multi dimensional to flatten array.
	 *
	 * @param array $array input array.
	 * @return array
	 */
	public static function array_flatten($array)
	{
		if (!is_array($array)) {
			return false;
		}
		$result = array();
		foreach ($array as $key => $value) {
			if (is_array($value)) {
				$result = array_merge($result, self::array_flatten($value));
			} else {
				$result[$key] = $value;
			}
		}
		return $result;
	}
	/**
	 * Term id list after ajax filter.
	 *
	 * @param object $efpe_query Event query array.
	 * @param object $taxonomies select Taxonomies.
	 * @return Array
	 */
	public static function efpe_all_other_taxonomy_term($efpe_query, $taxonomies)
	{
		$post_ids         = $efpe_query;
		$y                = 0;
		$final_term_list  = array();
		$taxonomies_count = count($taxonomies);
		while ($y < $taxonomies_count) {
			$term_list = array();
			foreach ($post_ids as $key => $id) {
				$ct_term = wp_get_post_terms($id, $taxonomies[$y], array('fields' => 'ids'));
				if (is_array($ct_term) && !empty($ct_term)) {
					array_push($term_list, $ct_term);
				}
			}
			$term_list                            = array_unique(self::array_flatten($term_list));
			$final_term_list[$taxonomies[$y]] = $term_list;
			$y++;
		}
		return $final_term_list;
	}

	/**
	 * All terms form the query
	 *
	 * @param  array  $efpe_query query arg.
	 * @param  string $taxonomy taxonomy.
	 * @return array
	 */
	public static function efpe_all_taxonomy_terms_form_the_query($efpe_query, $taxonomy)
	{
		$post_ids  = $efpe_query;
		$term_list = array();
		foreach ($post_ids as $key => $id) {
			$ct_term = wp_get_post_terms($id, $taxonomy, array('fields' => 'ids'));
			if (is_array($ct_term) && !empty($ct_term)) {
				array_push($term_list, $ct_term);
			}
		}
		return array_unique(self::array_flatten($term_list));
	}
	/**
	 * Live Filter reset after ajax request.
	 */
	public static function efpe_live_filter_reset()
	{
		if (isset($_POST['nonce']) && !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ta_efpe_nonce')) {
			return false;
		}
		$efpe_gl_id          = isset($_POST['id']) ? absint($_POST['id']) : '';
		// Initialize sanitized settings
		$efpe_settings = isset($_POST['efpe_settings']) ? $_POST['efpe_settings'] : array();

		// Sanitize efpe_settings if it exists and is an array
		// if (isset($_POST['efpe_settings']) && is_array($_POST['efpe_settings'])) {
		// 	$unslashed_settings = wp_unslash($_POST['efpe_settings']);
		// 	foreach ($unslashed_settings as $key => $value) {
		// 		$sanitized_key = sanitize_text_field($key);
		// 		if (is_array($value)) {
		// 			// Recursively sanitize nested arrays
		// 			$efpe_settings[$sanitized_key] = array_map('sanitize_text_field', $value);
		// 		} else {
		// 			$efpe_settings[$sanitized_key] = sanitize_text_field($value);
		// 		}
		// 	}
		// }
		$event_per_page       = isset($_POST['post_per_page']) ? sanitize_text_field(wp_unslash($_POST['post_per_page'])) : '';
		$efpe_event_limit     = isset($_POST['efpe_post_limit']) ? sanitize_text_field(wp_unslash($_POST['efpe_post_limit'])) : '';
		$author_id           = isset($_POST['author_id']) ? sanitize_text_field(wp_unslash($_POST['author_id'])) : '';
		$keyword             = isset($_POST['keyword']) ? sanitize_text_field(wp_unslash($_POST['keyword'])) : '';
		$orderby             = isset($_POST['orderby']) ? sanitize_text_field(wp_unslash($_POST['orderby'])) : '';
		$order               = isset($_POST['order']) ? sanitize_text_field(wp_unslash($_POST['order'])) : '';
		$taxonomy            = isset($_POST['taxonomy']) ? sanitize_text_field(wp_unslash($_POST['taxonomy'])) : '';
		$term_id             = isset($_POST['term_id']) ? sanitize_text_field(wp_unslash($_POST['term_id'])) : '';
		$efpe_lang           = isset($_POST['lang']) ? sanitize_text_field(wp_unslash($_POST['lang'])) : '';
		$last_filter         = isset($_POST['last_filter']) ? sanitize_text_field(wp_unslash($_POST['last_filter'])) : '';
		$paged               = isset($_POST['page']) ? sanitize_text_field(wp_unslash($_POST['page'])) : '';
		$custom_fields_array = isset($_POST['custom_fields_array']) ? sanitize_text_field(wp_unslash($_POST['custom_fields_array'])) : '';
		$selected_term_list  = isset($_POST['term_list']) ? $_POST['term_list'] : '';

		$view_options                 = get_post_meta($efpe_gl_id, 'efpe_view_options', true);
		$query_args                   = EventfulForElementorQueryinside::get_filtered_content($view_options, $efpe_gl_id, $layout_preset = 'default', $event_per_page, $efpe_event_limit, $efpe_settings);
		$query_args['fields']         = 'ids';
		$event_limit                   = isset($efpe_event_limit) && !empty($efpe_event_limit) ? $efpe_event_limit : 10000;
		$query_args['posts_per_page'] = $event_limit;
		$query_post_ids               = get_posts($query_args);
		$relation                     = isset($efpe_settings['taxonomy_relation']) ? $efpe_settings['taxonomy_relation'] : 'AND';
		$is_term_intersect            = true;
		if ('AND' !== $relation) {
			$is_term_intersect = false;
		}
		$query_args = EventfulForElementorFunctions::modify_query_params($query_args, $keyword, $author_id, $custom_fields_array, $orderby, $order, $selected_term_list, 0, $relation, $query_post_ids, $efpe_lang);
		$efpe_query  = array();
		self::efpe_live_filter($view_options, $efpe_settings, $efpe_event_limit, $query_args, $efpe_gl_id, $is_term_intersect, $selected_term_list, $last_filter);
		self::efpe_author_filter($view_options, $efpe_settings, $efpe_event_limit, $query_args, $author_id);

		wp_die();
	}

	/**
	 * Taxonomy Filter.
	 *
	 * @param array  $view_options options array.
	 * @param  array  $query_args  query array.
	 * @param  string $id shortcode id.
	 * @param  bool   $is_term_intersect is_ajax.
	 * @param  array  $selected_term_list selected term list.
	 * @param  string $last_filter last filter.
	 * @return void
	 */
	public static function efpe_live_filter($view_options, $efpe_settings, $efpe_event_limit, $query_args = '', $id = '', $is_term_intersect = true, $selected_term_list = array(), $last_filter = '')
	{
		$filter_by                    = isset($efpe_settings['efpe_advanced_filter']) ? $efpe_settings['efpe_advanced_filter'] : $view_options['efpe_advanced_filter'];
		$event_limit                   = isset($efpe_event_limit) && !empty($efpe_event_limit) ? $efpe_event_limit : $view_options['efpe_post_limit'];

		$query_args['posts_per_page'] = $event_limit;
		$query_args['fields']         = 'ids';
		if (in_array('taxonomy', $filter_by, true)) {
			$taxonomy_types = isset($efpe_settings['taxonomy_options']) && !empty($efpe_settings['taxonomy_options']) ? $efpe_settings['taxonomy_options'] : $view_options['taxonomy_options'];
			$relation       = isset($efpe_settings['taxonomy_relation']) ? $efpe_settings['taxonomy_relation'] : $view_options['taxonomy_relation'];
			if (!empty($taxonomy_types)) {
				$output         = '';
				$newterm_array  = array();
				$index          = 0;
				$taxonomies     = array();
				$taxonomy_count = count($taxonomy_types);
				while ($index < $taxonomy_count) {
					$add_filter = isset($taxonomy_types[$index]['add_filter_post']) ? $taxonomy_types[$index]['add_filter_post'] : '';

					if ($add_filter) {
						$taxonomy        = isset($taxonomy_types[$index]['select_taxonomy']) ? $taxonomy_types[$index]['select_taxonomy'] : '';
						$all_terms = get_terms($taxonomy);
						$all_term_ids = wp_list_pluck($all_terms, 'term_id');
						$terms           = isset($taxonomy_types[$index]['efpe_select_terms']) ? $taxonomy_types[$index]['efpe_select_terms'] : $all_term_ids;
						$all_post_ids    = get_posts($query_args);
						$event_limit      = count($all_post_ids);
						$url_last_filter = isset($_GET['slf']) ? sanitize_text_field(wp_unslash($_GET['slf'])) : '';

						if (!empty($selected_term_list) && is_array($selected_term_list)) {
							if ($last_filter == $taxonomy && 'AND' === $relation) {
								$new_query = $query_args;
								$tax_query = isset($new_query['tax_query']) ? $new_query['tax_query'] : array();
								if (!empty($tax_query)) {
									foreach ($tax_query as $key => $value) {
										if (is_array($value)) {
											if ($value['taxonomy'] == $taxonomy) {
												unset($tax_query[$key]);
											}
										}
									}
									$new_query['tax_query'] = $tax_query;
									$all_post_ids           = get_posts($new_query);
									$event_limit             = count($all_post_ids);
								}
							}
						} elseif ($url_last_filter == $taxonomy && 'AND' === $relation) {
							$new_query = $query_args;
							$tax_query = isset($new_query['tax_query']) ? $new_query['tax_query'] : array();
							if (!empty($tax_query)) {
								foreach ($tax_query as $key => $value) {
									if (is_array($value)) {
										if ($value['taxonomy'] == $taxonomy) {
											unset($tax_query[$key]);
										}
									}
								}
								$new_query['tax_query'] = $tax_query;
								$all_post_ids           = get_posts($new_query);
								$event_limit             = count($all_post_ids);
							}
						}

						$filter_options = isset($taxonomy_types[$index]['ajax_filter_options']) ? $taxonomy_types[$index]['ajax_filter_options'] : '';
						$all_text       = isset($taxonomy_types[$index]['ajax_rename_all_text']) && !empty($taxonomy_types[$index]['ajax_rename_all_text']) ? $taxonomy_types[$index]['ajax_rename_all_text'] : '';
						if ($is_term_intersect) {
							$new_terms = self::efpe_all_taxonomy_terms_form_the_query($all_post_ids, $taxonomy);
							$terms     = is_array($terms) ? $terms : array($terms);
							$terms     = array_intersect($terms, $new_terms);
						}

						$btn_style          = isset($taxonomy_types[$index]['ajax_filter_style']) ? $taxonomy_types[$index]['ajax_filter_style'] : 'fl_dropdown';
						$hide_taxonomy_name = isset($taxonomy_types[$index]['hide_taxonomy_name']) ? $taxonomy_types[$index]['hide_taxonomy_name'] : false;
						$show_taxonomy      = !$hide_taxonomy_name ? $taxonomy : '';
						$label              = isset($taxonomy_types[$index]['ajax_filter_label']) && !empty($taxonomy_types[$index]['ajax_filter_label']) ? $taxonomy_types[$index]['ajax_filter_label'] : $show_taxonomy;

						$hide_empty = isset($taxonomy_types[$index]['ajax_hide_empty']) ? $taxonomy_types[$index]['ajax_hide_empty'] : '';
						$show_count = isset($taxonomy_types[$index]['ajax_show_count']) ? $taxonomy_types[$index]['ajax_show_count'] : '';

						$efpe_live_filter_align = isset($taxonomy_types[$index]['efpe_live_filter_align']) ? $taxonomy_types[$index]['efpe_live_filter_align'] : 'center';
						if ($add_filter && !empty($terms) && !empty($taxonomy)) {
							$filter_item             = self::efpe_filter_style($btn_style, $taxonomy, $label, $all_text, $efpe_live_filter_align);
							$newterm_array[$index] = array($filter_item['first_item']);
							foreach ($terms as $term) {
								$selected = '';
								$checked  = '';
								if (!empty($selected_term_list) && is_array($selected_term_list)) {
									foreach ($selected_term_list as $key => $tax_type) {
										$cr_taxonomy = $tax_type['taxonomy'];
										$cr_terms    = $tax_type['term_id'];
										if (strpos($cr_terms, ',') !== false) {
											$cr_terms = explode(',', $cr_terms);
										} else {
											$cr_terms = array($cr_terms);
										}
										if ($cr_taxonomy == $taxonomy && in_array($term, $cr_terms)) {
											$selected = 'selected';
											$checked  = 'checked';
											break;
										}
									}
								}
								$p_term = get_term($term, $taxonomy);
								if (!is_wp_error($p_term) && !empty($p_term)) {
									$term_post_count = $p_term->count;
									$term_post_count = $term_post_count > $event_limit ? $event_limit : $term_post_count;
									if ($show_count && 'AND' == $relation) {
										$count_query              = $query_args;
										$count_query['tax_query'] = array(
											array(
												'taxonomy' => $taxonomy,
												'field'    => 'term_id',
												'terms'    => $term,
											),
										);
										$count_post_posts         = get_posts($count_query);
										$term_post_count          = count(array_intersect($count_post_posts, $all_post_ids));
									}

									if (!$hide_empty) {
										$push_item = self::efpe_filter_style($btn_style, $taxonomy, $label, $all_text, $efpe_live_filter_align, $show_count, $term, $p_term->name, $term_post_count, $id, $selected, $checked)['push_item'];
										array_push($newterm_array[$index], $push_item);
									} elseif ($hide_empty && $term_post_count > 0) {
										$push_item = self::efpe_filter_style($btn_style, $taxonomy, $label, $all_text, $efpe_live_filter_align, $show_count, $term, $p_term->name, $term_post_count, $id, $selected, $checked)['push_item'];
										array_push($newterm_array[$index], $push_item);
									}
								}
							}
							if (!$all_text) {
								$newterm_array[$index][1] = preg_replace('/ type=/i', ' selected checked type=', $newterm_array[$index][1]);
							}
							$tax_html = implode('', $newterm_array[$index]);
							$output   = $output . force_balance_tags($tax_html);
						}
					}
					$index++;
				}
				$allowed_tags = array(
					'form'  => array(
						'class' => array(),
						'style' => array(),
					),
					'p'     => array(),
					'div'   => array(
						'class' => array(),
						'style' => array(),
					),
					'label' => array(),
					'input' => array(
						'checked'       => array(),
						'type'          => array(),
						'name'          => array(),
						'data-taxonomy' => array(),
						'value'         => array(),
					),
				);

				echo wp_kses($output, $allowed_tags);
			}
		}
	}

	/**
	 * Live Filter reset after ajax request.
	 */
	public static function efpe_admin_live_filter_reset()
	{
		if (isset($_POST['nonce']) && !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'ta_efpe_nonce')) {
			return false;
		}
		$efpe_gl_id          = isset($_POST['id']) ? absint($_POST['id']) : '';
		// Initialize sanitized settings
		$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'])) {
		// 	$unslashed_settings = wp_unslash($_POST['efpe_settings']);
		// 	foreach ($unslashed_settings as $key => $value) {
		// 		$sanitized_key = sanitize_text_field($key);
		// 		if (is_array($value)) {
		// 			// Recursively sanitize nested arrays
		// 			$efpe_settings[$sanitized_key] = array_map('sanitize_text_field', $value);
		// 		} else {
		// 			$efpe_settings[$sanitized_key] = sanitize_text_field($value);
		// 		}
		// 	}
		// }
		$event_per_page       = isset($_POST['post_per_page']) ? sanitize_text_field(wp_unslash($_POST['post_per_page'])) : '';
		$efpe_event_limit     = isset($_POST['efpe_post_limit']) ? sanitize_text_field(wp_unslash($_POST['efpe_post_limit'])) : '';
		$author_id           = isset($_POST['author_id']) ? sanitize_text_field(wp_unslash($_POST['author_id'])) : '';
		$keyword             = isset($_POST['keyword']) ? sanitize_text_field(wp_unslash($_POST['keyword'])) : '';
		$orderby             = isset($_POST['orderby']) ? sanitize_text_field(wp_unslash($_POST['orderby'])) : '';
		$order               = isset($_POST['order']) ? sanitize_text_field(wp_unslash($_POST['order'])) : '';
		$taxonomy            = isset($_POST['taxonomy']) ? sanitize_text_field(wp_unslash($_POST['taxonomy'])) : '';
		$efpe_lang           = isset($_POST['lang']) ? sanitize_text_field(wp_unslash($_POST['lang'])) : '';
		$term_id             = isset($_POST['term_id']) ? sanitize_text_field(wp_unslash($_POST['term_id'])) : '';
		$last_filter         = isset($_POST['last_filter']) ? sanitize_text_field(wp_unslash($_POST['last_filter'])) : '';
		$paged               = isset($_POST['page']) ? sanitize_text_field(wp_unslash($_POST['page'])) : '';
		$custom_fields_array = isset($_POST['custom_fields_array']) ? sanitize_text_field(wp_unslash($_POST['custom_fields_array'])) : '';
		$selected_term_list  = isset($_POST['term_list']) ? $_POST['term_list'] : '';
		// $selected_term_list  = isset($_POST['term_list']) ? sanitize_text_field(wp_unslash($_POST['term_list'])) : '';
		$settings            = array();
		if (isset($_POST['data'])) {
			$sanitized_data = sanitize_text_field(wp_unslash($_POST['data']));

			parse_str($sanitized_data, $settings);
		} else {
			$settings = [];
		}

		$layout                       = $settings['efpe_layouts'];
		$layout_preset                = isset($layout['efpe_layout_preset']) ? $layout['efpe_layout_preset'] : '';
		$view_options                 = $settings['efpe_view_options'];
		$query_args                   = EventfulForElementorQueryinside::get_filtered_content($view_options, $efpe_gl_id, $layout_preset = 'default', $event_per_page, $efpe_event_limit, $efpe_settings);
		$query_args['fields']         = 'ids';
		$new_query_args               = $query_args;
		$event_limit                   = isset($view_options['efpe_post_limit']) && !empty($view_options['efpe_post_limit']) ? $view_options['efpe_post_limit'] : 10000;
		$query_args['posts_per_page'] = $event_limit;
		$query_post_ids               = get_posts($new_query_args);

		$relation          = isset($efpe_settings['taxonomies_relation']) ? $efpe_settings['taxonomies_relation'] : 'AND';
		$is_term_intersect = true;
		if ('AND' !== $relation) {
			$is_term_intersect = false;
		}
		$query_args = EventfulForElementorFunctions::modify_query_params($query_args, $keyword, $author_id, $custom_fields_array, $orderby, $order, $selected_term_list, 0, $relation, $query_post_ids, $efpe_lang);
		self::efpe_live_filter($view_options, $efpe_settings, $efpe_event_limit, $query_args, $efpe_gl_id, $is_term_intersect, $selected_term_list, $last_filter);
		self::efpe_author_filter($view_options, $efpe_settings, $efpe_event_limit, $query_args, $author_id);
		wp_die();
	}


	/**
	 * Final showing terms list
	 *
	 * @param string $taxonomy taxonomy.
	 * @param string $selected_taxonomy Selected taxonomy.
	 * @param array  $all_term all terms id.
	 * @param array  $terms terms.
	 * @param int    $tax_settings_count taxonomy count.
	 * @param array  $selected_taxs Selected taxonomys.
	 * @param array  $is_other_query_active query.
	 * @return object
	 */
	public static function efpe_showing_term($taxonomy, $selected_taxonomy, $all_term, $terms, $tax_settings_count, $selected_taxs, $is_other_query_active = false)
	{
		if ($selected_taxs) {
			if (($selected_taxonomy === $taxonomy && $tax_settings_count < 1) || (count($selected_taxs) <= 1 && $selected_taxs[0] === $taxonomy)) {
				$final_terms = $terms;
			} else {
				$final_terms = array_intersect($all_term, $terms);
			}
		} else {
			if ($is_other_query_active) {
				$final_terms = array_intersect($all_term, $terms);
			} else {
				$final_terms = $terms;
			}
		}

		return $final_terms;
	}

	/**
	 * Author filter bar.
	 *
	 * @param mixed  $view_options options.
	 * @param array  $query_args custom query array.
	 * @param string $current_author current author.
	 * @return void
	 */
	public static function efpe_author_filter($view_options, $efpe_settings, $efpe_event_limit, $query_args, $current_author = '')
	{
		$filter_by            = isset($efpe_settings['efpe_advanced_filter']) ? $efpe_settings['efpe_advanced_filter'] : $view_options['efpe_advanced_filter'];
		$event_limit           = isset($efpe_event_limit) && !empty($efpe_event_limit) ? $efpe_event_limit : $view_options['efpe_post_limit'];
		$efpe_select_post_type = 'tribe_events';
		if (in_array('author', $filter_by, true)) {
			$add_filter_post       = isset($efpe_settings['author_live_filters']) ? $efpe_settings['author_live_filters'] : $view_options['author_live_filters'];
			$efpe_select_author_by  = isset($efpe_settings['select_author']) ? $efpe_settings['select_author'] : $view_options['select_author'];
			$btn_type              = isset($efpe_settings['author_filter_style']) ? $efpe_settings['author_filter_style'] : $view_options['author_filter_style'];
			$author_label                 = isset($view_options['author_filter_label']) && !empty($view_options['author_filter_label']) ? $view_options['author_filter_label'] : 'Author';
			$label                 = isset($efpe_settings['author_filter_label']) && !empty($efpe_settings['author_filter_label']) ? $efpe_settings['author_filter_label'] : $author_label;
			$all_text              = isset($efpe_settings['author_rename_all_text']) ? $efpe_settings['author_rename_all_text'] : $view_options['author_rename_all_text'];
			$hide_empty            = isset($efpe_settings['author_hide_empty']) ? $efpe_settings['author_hide_empty'] : $view_options['author_hide_empty'];
			$show_count            = isset($efpe_settings['author_show_count']) ? $efpe_settings['author_show_count'] : $view_options['author_show_count'];
			$efpe_live_filter_align = isset($efpe_settings['author_live_filter_align']) ? $efpe_settings['author_live_filter_align'] : $view_options['author_live_filter_align'];

			if ($add_filter_post  && is_array($efpe_select_author_by)) {
				$filter_item   = self::efpe_author_filter_style($btn_type, $label, $all_text, $efpe_live_filter_align);
				$newterm_array = array($filter_item['first_item']);
				foreach ($efpe_select_author_by as $author_id) {
					$author_name = get_the_author_meta('display_name', $author_id);
					// Prepare the query arguments.
					$query_args['posts_per_page'] = (int) $event_limit;
					$query_args['author__in']     = $author_id;
					$query_args['fields']         = 'ids';
					// Get all the posts.
					if ($current_author === $author_id) {
						$selected = 'selected';
						$checked  = 'checked';
					} else {
						$selected = '';
						$checked  = '';
					}
					$author_posts      = get_posts($query_args);
					$author_post_count = count($author_posts);
					if (!$hide_empty) {
						$push_item = self::efpe_author_filter_style($btn_type, $label, $all_text, $efpe_live_filter_align, $author_id, $author_name, $author_post_count, $show_count, $selected, $checked)['push_item'];
						array_push($newterm_array, $push_item);
					} elseif ($hide_empty && $author_post_count > 0) {
						$push_item = self::efpe_author_filter_style($btn_type, $label, $all_text, $efpe_live_filter_align, $author_id, $author_name, $author_post_count, $show_count, $selected, $checked)['push_item'];
						array_push($newterm_array, $push_item);
					}
				}
				$tax_html = implode('', $newterm_array);
				$output   = '';
				$output   = $output . force_balance_tags($tax_html);
				$allowed_tags = array(
					'form'  => array(
						'class' => array(),
						'style' => array(),
					),
					'p'     => array(),
					'div'   => array(
						'class' => array(),
						'style' => array(),
					),
					'label' => array(),
					'input' => array(
						'checked'       => array(),
						'type'          => array(),
						'name'          => array(),
						'data-taxonomy' => array(),
						'value'         => array(),
					),
				);

				echo wp_kses($output, $allowed_tags);
			}
		}
	}

	/**
	 * Orderby filter bar
	 *
	 * @param mixed  $view_options options.
	 * @param array  $query_args custom query.
	 * @param string $sid shortcode id.
	 * @return void
	 */
	public static function efpe_orderby_filter_bar($view_options, $efpe_settings, $query_args, $sid = null)
	{
		$filter_by = isset($efpe_settings['efpe_advanced_filter']) ? $efpe_settings['efpe_advanced_filter'] : $view_options['efpe_advanced_filter'];
		if (in_array('sortby', $filter_by, true)) {
			$add_filter_post        = isset($efpe_settings['sortby_live_filters']) ? $efpe_settings['sortby_live_filters'] : $view_options['sortby_live_filters'];
			$efpe_add_filter_orderby = isset($efpe_settings['efpe_add_filter_orderby']) ? $efpe_settings['efpe_add_filter_orderby'] : $view_options['efpe_add_filter_orderby'];
			$all_text               = isset($efpe_settings['sortby_rename_all_text']) ? $efpe_settings['sortby_rename_all_text'] : $view_options['sortby_rename_all_text'];
			$btn_type               = isset($efpe_settings['sortby_filter_style']) ? $efpe_settings['sortby_filter_style'] : $view_options['sortby_filter_style'];
			$label                  = isset($efpe_settings['sortby_filter_label']) && !empty($efpe_settings['sortby_filter_label']) ? $efpe_settings['sortby_filter_label'] : $view_options['sortby_filter_label'];
			$efpe_live_filter_align  = isset($efpe_settings['sortby_live_filter_align']) ? $efpe_settings['sortby_live_filter_align'] :  $view_options['sortby_live_filter_align'];

			if ($add_filter_post && is_array($efpe_add_filter_orderby)) {
				$filter_item   = self::efpe_orderby_filter_style($btn_type, $label, $all_text, $efpe_live_filter_align);
				$newterm_array = array($filter_item['first_item']);
				foreach ($efpe_add_filter_orderby as $orderby) {
					$push_item = self::efpe_orderby_filter_style($btn_type, $label, $all_text, $efpe_live_filter_align, $orderby, $sid)['push_item'];
					array_push($newterm_array, $push_item);
				}
				$tax_html = implode('', $newterm_array);
				$output   = '';
				$output   = $output . force_balance_tags($tax_html);
				$allowed_tags = array(
					'form'  => array(
						'class' => array(),
						'style' => array(),
					),
					'p'     => array(),
					'div'   => array(
						'class' => array(),
						'style' => array(),
					),
					'label' => array(),
					'input' => array(
						'checked'       => array(),
						'type'          => array(),
						'name'          => array(),
						'data-taxonomy' => array(),
						'value'         => array(),
					),
				);

				echo $output;
			}
		}
	}

	/**
	 * Order filter button.
	 *
	 * @param mixed  $view_options options.
	 * @param string $sid shortcode id.
	 * @return void
	 */
	public static function efpe_order_filter_bar($view_options, $efpe_settings, $sid = null)
	{
		$filter_by = isset($efpe_settings['efpe_advanced_filter']) ? $efpe_settings['efpe_advanced_filter'] : $view_options['efpe_advanced_filter'];
		if (in_array('sortby', $filter_by)) {
			$add_filter_post         	= isset($efpe_settings['add_order_filter_post']) ? $efpe_settings['add_order_filter_post'] : $view_options['add_order_filter_post'];
			$select_filter_order 		= isset($efpe_settings['select_filter_order']) ? $efpe_settings['select_filter_order'] : $view_options['select_filter_order'];

			$efpe_add_filter_orderby  	= array('DESC', 'ASC');
			$btn_type                	= isset($efpe_settings['order_filter_options']) ? $efpe_settings['order_filter_options'] : $view_options['order_filter_options'];
			$label                   	= isset($efpe_settings['order_filter_label']) ? $efpe_settings['order_filter_label'] : $view_options['order_filter_label'];
			$efpe_live_filter_align   	= isset($efpe_settings['efpe_live_filter_align']) ? $efpe_settings['efpe_live_filter_align'] : $view_options['efpe_live_filter_align'];
			if ($add_filter_post) {
				$filter_item   	= self::efpe_order_filter_style($btn_type, $label, $efpe_live_filter_align);
				$newterm_array 	= array($filter_item['first_item']);
				foreach ($efpe_add_filter_orderby as $order) {
					$push_item 	= self::efpe_order_filter_style($btn_type, $label, $efpe_live_filter_align, $order, $select_filter_order, $sid)['push_item'];
					array_push($newterm_array, $push_item);
				}
				$tax_html 		= implode('', $newterm_array);
				$output   		= '';
				$output   		= $output . force_balance_tags($tax_html);
				$allowed_tags = array(
					'form'  => array(
						'class' => array(),
						'style' => array(),
					),
					'p'     => array(),
					'div'   => array(
						'class' => array(),
					),
					'label' => array(),
					'input' => array(
						'checked'       => array(),
						'type'          => array(),
						'name'          => array(),
						'data-taxonomy' => array(),
						'value'         => array(),
					),
				);

				echo wp_kses($output, $allowed_tags);
			}
		}
	}

	/**
	 * Author filter type.
	 *
	 * @param string  $btn_type button type.
	 * @param string  $label author filter label.
	 * @param string  $all_text all text.
	 * @param int     $align alignment.
	 * @param int     $author_id author id.
	 * @param string  $author_name user name.
	 * @param int     $author_post_count  user post count.
	 * @param boolean $show_count show/hide post count.
	 * @param string  $selected select.
	 * @param string  $checked check.
	 */
	public static function efpe_author_filter_style($btn_type, $label, $all_text, $align = 'center', $author_id = null, $author_name = null, $author_post_count = null, $show_count = true, $selected = '', $checked = '')
	{
		if ($show_count) {
			$post_count_markup = '<span class="efpe-count">(' . $author_post_count . ')</span>';
		} else {
			$post_count_markup = '';
		}

		$final_author_url_value = isset($_GET['efpe_author_id']) ? sanitize_text_field(wp_unslash($_GET['efpe_author_id'])) : '';
		if ($final_author_url_value == $author_id) {
			$a_selected = 'selected';
			$a_checked  = 'checked';
		} else {
			$a_selected = $selected;
			$a_checked  = $checked;
		}
		if ('fl_radio' === $btn_type) {
			$all_label  = !empty($all_text) ? $all_text : '';
			$first_item = '<div class="efpe-author-filter efpe-bar" style="text-align:' . esc_attr($align) . ';"><p>' . esc_html($label) . '</p><div class="fl_radio"><label><input checked type="radio" name="author" value="all">' . $all_label . '</label></div>';
			$push_item  = '<div class="fl_radio"><label><input name="author" type="radio" ' . $a_checked . ' value="' . esc_attr($author_id) . '">' . esc_attr($author_name) . $post_count_markup . '</label></div>';
		} elseif ('fl_btn' === $btn_type) {
			$all_label  = !empty($all_text) ? '<div>' . $all_text . '</div>' : '';
			$first_item = '<div class="efpe-author-filter efpe-bar fl_button" style="text-align:' . esc_attr($align) . ';"> <p>' . esc_html($label) . '</p><div class="fl_radio"><label><input checked type="radio" name="author" value="all">' . $all_label . '</label></div>';
			$push_item  = '<div class="fl_radio"><label><input name="author" type="radio" ' . $a_checked . ' value="' . esc_attr($author_id) . '"><div>' . esc_attr($author_name) . $post_count_markup . '</div></label></div>';
		} else {
			$all_label  = !empty($all_text) ? $all_text : '';
			$first_item = '<div class="efpe-author-filter efpe-bar" style="text-align:' . esc_attr($align) . ';"> <label class="efpe-label">' . esc_html($label) . '</label><select><option  name="author" value="all">' . $all_label . '</option>';
			$push_item  = '<option name="author" value="' . esc_attr($author_id) . '" ' . $a_selected . '>' . esc_attr($author_name) . $post_count_markup . ' </option>';
		}
		$filter_output = array(
			'first_item' => $first_item,
			'push_item'  => $push_item,
		);
		return $filter_output;
	}

	/**
	 * Custom field filter style
	 *
	 * @param  string $btn_type btn_type.
	 * @param  string $label label.
	 * @param  string $all_text all text.
	 * @param  string $align alignment.
	 * @param  string $field_key key.
	 * @param  string $value  field value.
	 * @param  string $p_count post count.
	 * @param  string $id shortcode id.
	 * @param  string $selected selected text.
	 * @param  string $checked checked.
	 * @param  bool   $show_count is show post count.
	 * @return statement
	 */
	public static function efpe_custom_field_filter_style($btn_type, $label = 'Custom field', $all_text = 'All', $align = 'center', $field_key = null, $value = null, $p_count = '', $id = '', $selected = '', $checked = '', $show_count = false)
	{
		$post_count_markup = '';
		if ($show_count) {
			$post_count_markup = '<span class="efpe-count">(' . $p_count . ')</span>';
		}
		$a_selected       = $selected;
		$a_checked        = $checked;
		$capitalize_value = ucfirst(apply_filters('efpe_custom_meta_filter_value', $value, $field_key)) . $post_count_markup;

		$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 == $id) {
				$filter_value = isset($_GET["cf$field_key"]) ? sanitize_text_field(wp_unslash($_GET["cf$field_key"])) : '';
				if (!empty($filter_value)) {
					if (strpos($filter_value, ',') !== false) {
						$filter_value = explode(',', $filter_value);
					}

					if (is_array($filter_value)) {
						if (in_array($value, $filter_value)) {
							$a_checked  = 'checked';
							$a_selected = 'selected';
						} else {
							$is_checked  = $checked;
							$is_selected = $selected;
						}
					} else {
						if ($filter_value == $value) {
							$a_checked  = 'checked';
							$a_selected = 'selected';
						} else {
							$a_checked  = $checked;
							$a_selected = $selected;
						}
					}
				}
			}
		}

		if ('fl_checkbox' === $btn_type) {
			$first_item = '<div class="efpe-custom-field-filter-checkbox efpe-bar" style="text-align:' . esc_attr($align) . ';"><p>' . esc_html($label) . '</p>';
			$push_item  = '<div class="fl_checkbox"><label><input name="' . esc_attr($field_key) . '" type="checkbox" ' . $a_checked . '  value="' . esc_attr($value) . '">' . wp_kses_post($capitalize_value) . '</span></label></div>';
		} elseif ('fl_radio' === $btn_type) {
			$all_label  = !empty($all_text) ? $all_text : '';
			$first_item = '<div class="efpe-custom-field-filter efpe-bar" style="text-align:' . esc_attr($align) . ';"><p>' . esc_html($label) . '</p><div class="fl_radio"><label><input checked type="radio" name="' . esc_attr($field_key) . '" value="all">' . $all_label . '</label></div>';
			$push_item  = '<div class="fl_radio"><label><input name="' . esc_attr($field_key) . '" type="radio" ' . $a_checked . ' value="' . esc_attr($value) . '">' . wp_kses_post($capitalize_value) . '</label></div>';
		} elseif ('fl_btn' === $btn_type) {
			$all_label  = !empty($all_text) ? '<div>' . esc_html($all_text) . '</div>' : '';
			$first_item = '<div class="efpe-custom-field-filter efpe-bar fl_button filter-' . $field_key . '" style="text-align:' . esc_attr($align) . ';"> <p>' . esc_html($label) . '</p><div class="fl_radio"><label><input checked type="radio" name="' . esc_attr($field_key) . '" value="all">' . $all_label . '</label></div>';
			$push_item  = '<div class="fl_radio"><label><input name="' . esc_attr($field_key) . '" type="radio" ' . $a_checked . ' value="' . esc_attr($value) . '"><div>' . wp_kses_post($capitalize_value) . '</div></label></div>';
		} else {
			$all_label  = !empty($all_text) ? $all_text : '';
			$first_item = '<div class="efpe-custom-field-filter efpe-bar" style="text-align:' . esc_attr($align) . ';"> <label class="efpe-label">' . esc_html($label) . '</label><select><option  name="' . $field_key . '" value="all">' . $all_label . '</option>';
			$push_item  = '<option name="' . $field_key . '" value="' . $value . '" ' . $a_selected . '>' . wp_kses_post($capitalize_value) . ' </option>';
		}
		$filter_output = array(
			'first_item' => $first_item,
			'push_item'  => $push_item,
		);
		return $filter_output;
	}
	/**
	 * Order by filter bar style.
	 *
	 * @param string $btn_type button type.
	 * @param string $label order by label.
	 * @param string $align alignment.
	 * @param string $orderby order text.
	 * @param string $sid shortcode id.
	 * @return array
	 */
	public static function efpe_orderby_filter_style($btn_type, $label, $all_text = 'None', $align = 'center', $orderby = null, $sid = null)
	{
		$filter_url_value        = isset($_SERVER['QUERY_STRING']) ? sanitize_text_field(wp_unslash($_SERVER['QUERY_STRING'])) : '';
		$final_orderby_url_value = '';
		if (!empty($filter_url_value)) {
			$shortcode_id = isset($_GET['sps']) ? sanitize_text_field(wp_unslash($_GET['sps'])) : '';
			if ($shortcode_id == $sid) {
				$final_orderby_url_value = isset($_GET['efpe_orderby']) ? sanitize_text_field(wp_unslash($_GET['efpe_orderby'])) : '';
			}
		}

		if ($final_orderby_url_value == $orderby) {
			$is_selected = 'selected';
			$is_checked  = 'checked';
		} else {
			$is_selected = '';
			$is_checked  = '';
		}

		if ('fl_radio' === $btn_type) {
			$first_item = '<div class="efpe-order-by efpe-bar" style="text-align:' . esc_attr($align) . ';"><p>' . esc_html($label) . '</p><div class="fl_radio"><label><input checked type="radio" name="orderby" value="">' . esc_html($all_text) . '</label></div>';
			$push_item  = '<div class="fl_radio"><label><input name="orderby" type="radio"  ' . $is_checked . ' value="' . $orderby . '">' . $orderby . '</label></div>';
		} elseif ('fl_btn' === $btn_type) {
			$first_item = '<div class="efpe-order-by efpe-bar fl-btn" style="text-align:' . esc_attr($align) . ';"><p>' . esc_html($label) . '</p> <div class="fl_radio"><label><input checked type="radio" name="orderby" value=""><div>' . esc_html($all_text) . '</div></label></div>';
			$push_item  = '<div class="fl_radio"><label><input type="radio" name="orderby" ' . $is_checked . ' value="' . $orderby . '"><div>' . $orderby . '</div></label></div>';
		} else {
			$first_item = '<div class="efpe-order-by efpe-bar" style="text-align:' . esc_attr($align) . ';"><p>' . esc_html($label) . '</p><select><option  name="orderby" value="">' . esc_html($all_text) . '</option>';
			$push_item  = '<option name="orderby" ' . $is_selected . ' value="' . $orderby . '">' . $orderby . '</option>';
		}
		$filter_output = array(
			'first_item' => $first_item,
			'push_item'  => $push_item,
		);
		return $filter_output;
	}

	/**
	 * Order filter style
	 *
	 * @param string $btn_type button type.
	 * @param string $label order filter label.
	 * @param string $align alignment text.
	 * @param string $order order text.
	 * @param string $select_order selected order.
	 * @param string $sid shortcode id.
	 */
	public static function efpe_order_filter_style($btn_type, $label, $align = 'center', $order = null, $select_order = null, $sid = null)
	{
		$final_order_url_value = '';
		$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 == $sid) {
				$final_order_url_value = isset($_GET['efpe_order']) ? sanitize_text_field(wp_unslash($_GET['efpe_order'])) : '';
			}
		}

		if ($final_order_url_value == $order) {
			$checked  = 'checked';
			$selected = 'selected';
		} else {
			$selected = '';
			$checked  = '';
		}
		if ('fl_radio' === $btn_type) {
			$first_item = '<div class="efpe-order efpe-bar" style="text-align:' . esc_attr($align) . ';"><p>' . esc_html($label) . '</p>';
			$push_item  = '<div class="fl_radio"><label><input name="order" ' . $checked . ' type="radio" value="' . $order . '">' . $order . '</label></div>';
		} elseif ('fl_btn' === $btn_type) {
			$first_item = '<div class="efpe-order efpe-bar fl-btn" style="text-align:' . esc_attr($align) . ';"><p>' . esc_html($label) . '</p>';
			$push_item  = '<div class="fl_radio"><label><input type="radio" ' . $checked . ' name="order" value="' . $order . '"><div>' . $order . '</div></label></div>';
		} else {
			$first_item = '<div class="efpe-order efpe-bar" style="text-align:' . esc_attr($align) . ';"><p>' . esc_html($label) . '</p><select>';
			$push_item  = '<option name="order" ' . $selected . ' value="' . $order . '">' . $order . '</option>';
		}
		$filter_output = array(
			'first_item' => $first_item,
			'push_item'  => $push_item,
		);
		return $filter_output;
	}

	/**
	 * Live search bar
	 *
	 * @param int    $view_options options.
	 * @param string $sid shortcode id.
	 * @return void
	 */
	public static function efpe_live_search_bar($view_options, $efpe_settings, $sid = null)
	{
		$filter_by        = isset($efpe_settings['efpe_advanced_filter']) ? $efpe_settings['efpe_advanced_filter'] : $view_options['efpe_advanced_filter'];
		$final_keyword    = '';
		$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 == $sid) {
				$final_keyword = isset($_GET['efpe_keyword']) ? sanitize_text_field(wp_unslash($_GET['efpe_keyword'])) : '';
			}
		}
		if (in_array('keyword', $filter_by, true)) {
			$add_filter_post       = isset($efpe_settings['add_search_filter_post']) ? $efpe_settings['add_search_filter_post'] : $view_options['add_search_filter_post'];
			if ($add_filter_post) {
				$label                 = isset($efpe_settings['keyword_filter_label']) && !empty($efpe_settings['keyword_filter_label']) ? $efpe_settings['keyword_filter_label'] : $view_options['keyword_filter_label'];
				$efpe_live_filter_align = isset($efpe_settings['keyword_live_filter_align']) ? $efpe_settings['keyword_live_filter_align'] : $view_options['keyword_live_filter_align'];
				echo '<div class="efpe-ajax-search efpe-bar" style="text-align:' . esc_attr($efpe_live_filter_align) . ';"><label class="efpe-label">' . wp_kses_post($label) . ' <input type="text" value="' . esc_attr($final_keyword) . '" class="efpe-search-field" placeholder="Search..."></label></div>';
			}
		}
	}
}
