<?php

namespace Unlockafe_addons\Traits;

use Elementor\Controls_Manager;

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

trait Widget_helper
{
	public function get_pro_notice()
	{

		// skip for pro users
		if ('lite' == \Unlockafe_addons\Unlockafe_addons::plugin_type() && true == false) {
			$this->start_controls_section(
				'ekit_section_pro',
				[
					'label' => __('Unlock Premium', 'unlock-addons-for-elementor'),
				]
			);

			$this->add_control(
				'custom_panel_alert',
				[
					'type' => \Elementor\Controls_Manager::ALERT,
					'alert_type' => 'info',
					'heading' => esc_html__('Unlock All widgets', 'unlock-addons-for-elementor'),
					'content' => '<span class="ekit-widget-pro-feature"> Get the  <a href="https://wprealizer.com/" target="_blank">Pro version</a> for more awesome elements and powerful modules.</span>',
				]
			);


			$this->end_controls_section();
		}
	}

	protected function get_upsale_data()
	{
		return [
			'condition' => ! \Elementor\Utils::has_pro(),
			'image' => esc_url(ELEMENTOR_ASSETS_URL . 'images/go-pro.svg'),
			'image_alt' => esc_attr__('Upgrade', 'unlock-addons-for-elementor'),
			'title' => esc_html__('Upgrade Pro', 'unlock-addons-for-elementor'),
			'description' => esc_html__('Get the premium version of the widget and grow your website capabilities.', 'unlock-addons-for-elementor'),
			'upgrade_url' => esc_url('https://unlockaddons.com/unlock-addons-for-elementor/'),
			'upgrade_text' => esc_html__('Upgrade Now', 'unlock-addons-for-elementor'),
		];
	}

	public function print_paragraph($text = '', $allowed_tags = [], $class = '')
	{
		if (empty($text))
			return;
		$class = $class != '' ? 'class=' . $class : '';
		echo '<p ' . wp_kses($class, true) . '>' . wp_kses($text, $allowed_tags) . '</p>';
	}


	public function get_layout_controls($array = [])
	{
		/**
		 * 
		 * Layout
		 */
		$this->start_controls_section(
			'layout',
			[
				'label' => esc_html__('Layout', 'unlock-addons-for-elementor'),
			]
		);

		$this->add_control(
			'layout_control',
			[
				'label' => esc_html__('Layout Style', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::SELECT,
				'default' => 'layout-1',
				'options' => $array
			]
		);

		$this->end_controls_section();
	}
	public function get_slider_controls($array = [])
	{
		/**
		 * 
		 * Slider
		 */
		$this->start_controls_section(
			'slider',
			[
				'label' => esc_html__('Slider', 'unlock-addons-for-elementor'),
			]
		);

		$this->add_control(
			'slider_control',
			[
				'label' => esc_html__('Slider Style', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::SELECT,
				'default' => 'slider-1',
				'options' => $array
			]
		);

		$this->end_controls_section();
	}

	/**
	 * Basic style controls
	 * 
	 * @since 1.0.0
	 * @param string $control_id
	 * @param string $control_name
	 * @param string $control_selector
	 * @param array|null $condition
	 */
	protected function tp_basic_style_controls($control_id = null, $control_name = null, $control_selector = null, $condition = null)
	{
		if (empty($control_id) || empty($control_name) || empty($control_selector)) {
			return;
		}

		$section_args = [
			'label' => esc_html__($control_name, 'unlock-addons-for-elementor'),
			'tab' => \Elementor\Controls_Manager::TAB_STYLE,
		];

		if ($condition) {
			$section_args['condition'] = [
				'wpr_design_style' => $condition
			];
		}

		$this->start_controls_section(
			'tp_' . $control_id . '_styling',
			$section_args
		);

		$this->start_controls_tabs(
			'tp_' . $control_id . '_tabs_style',
		);

		// Normal State Tab
		$this->start_controls_tab(
			'tp_' . $control_id . '_tab_style',
			[
				'label' => esc_html__('Normal', 'unlock-addons-for-elementor'),
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_normal_color',
			[
				'label' => esc_html__('Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector => 'color: {{VALUE}};',
				],
			]
		);

		$this->end_controls_tab();

		// Hover State Tab
		$this->start_controls_tab(
			'tp_' . $control_id . '_tab_hover_style',
			[
				'label' => esc_html__('Hover', 'unlock-addons-for-elementor'),
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_hover_color',
			[
				'label' => esc_html__('Hover Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector . ':hover' => 'color: {{VALUE}};',
				],
			]
		);

		$this->end_controls_tab();
		$this->end_controls_tabs();

		$this->add_control(
			'tp_' . $control_id . '_tab_hover_transition',
			[
				'label' => esc_html__('Transition Duration', 'unlock-addons-for-elementor') . ' (s)',
				'type' => \Elementor\Controls_Manager::SLIDER,
				'range' => [
					'' => [
						'min' => 0,
						'max' => 10,
						'step' => 0.1,
					],
				],
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector => 'transition: all {{SIZE}}s ease-in-out; -webkit-transition: all {{SIZE}}s ease-in-out;',
				],
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			[
				'name' => 'tp_' . $control_id . '_typography',
				'label' => esc_html__('Typography', 'unlock-addons-for-elementor'),
				'selector' => '{{WRAPPER}} ' . $control_selector,
			]
		);

		$this->add_responsive_control(
			'tp_' . $control_id . '_padding',
			[
				'label' => esc_html__('Padding', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => ['px', '%', 'em'],
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);

		$this->add_responsive_control(
			'tp_' . $control_id . '_margin',
			[
				'label' => esc_html__('Margin', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => ['px', '%', 'em'],
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);

		$this->end_controls_section();
	}

	/**
	 * Link controls style
	 * 
	 * @since 1.0.0
	 * @param string $control_id
	 * @param string $control_name
	 * @param string $control_selector
	 * @param array|null $condition
	 */
	protected function tp_link_controls_style($control_id = 'sec', $control_name = 'Button', $control_selector = '.tp-btn', $condition = null)
	{
		$section_args = [
			'label' => esc_html__($control_name, 'unlock-addons-for-elementor'),
			'tab' => \Elementor\Controls_Manager::TAB_STYLE,
		];

		if ($condition) {
			$section_args['condition'] = [
				'wpr_design_style' => $condition
			];
		}

		$this->start_controls_section(
			'tp_' . $control_id . '_button',
			$section_args
		);

		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			[
				'name' => 'tp_' . $control_id . '_typography',
				'selector' => '{{WRAPPER}} ' . $control_selector . '',
			]
		);

		$this->start_controls_tabs('tp_' . $control_id . '_button_tabs');

		// Normal State Tab
		$this->start_controls_tab('tp_' . $control_id . '_btn_normal', ['label' => esc_html__('Normal', 'unlock-addons-for-elementor')]);

		$this->add_control(
			'tp_' . $control_id . '_btn_normal_text_color',
			[
				'label' => esc_html__('Text Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector . '' => 'color: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_btn_normal_bg_color',
			[
				'label' => esc_html__('Background Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector . '' => 'background: {{VALUE}} !important;',
				],
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Box_Shadow::get_type(),
			[
				'name' => 'tp_' . $control_id . '_btn_box_shadow',
				'label' => esc_html__('Box Shadow', 'unlock-addons-for-elementor'),
				'selector' => '{{WRAPPER}} ' . $control_selector . '',
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Border::get_type(),
			[
				'name' => 'tp_' . $control_id . '_btn_normal_border_style',
				'selector' => '{{WRAPPER}} ' . $control_selector,
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_btn_normal_border_radius',
			[
				'label' => esc_html__('Border Radius', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => ['px', '%', 'em', 'rem'],
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);

		$this->end_controls_tab();

		// Hover State Tab
		$this->start_controls_tab('tp_' . $control_id . '_btn_hover', ['label' => esc_html__('Hover', 'unlock-addons-for-elementor')]);

		$this->add_control(
			'tp_' . $control_id . '_btn_hover_text_color',
			[
				'label' => esc_html__('Text Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector . ':hover' => 'color: {{VALUE}} !important;',
				],
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_btn_hover_bg_color',
			[
				'label' => esc_html__('Background Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector . ':hover' => 'background: {{VALUE}} !important;',
				],
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Box_Shadow::get_type(),
			[
				'name' => 'tp_' . $control_id . '_btn_hover_box_shadow',
				'label' => esc_html__('Box Shadow', 'unlock-addons-for-elementor'),
				'selector' => '{{WRAPPER}} ' . $control_selector . ':hover',
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_btn_hover_border_color',
			[
				'label' => esc_html__('Border Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector . ':hover' => 'border-color: {{VALUE}};',
				],
			]
		);

		$this->end_controls_tab();
		$this->end_controls_tabs();

		$this->end_controls_section();
	}

	/**
	 * Single icon control
	 * 
	 * @since 1.0.0
	 * @param string $control_id
	 * @param string $condition_key
	 * @param string $conditions_value
	 */
	protected function tp_single_icon_control($control_id = null, $condition_key = null, $conditions_value = 'layout-1')
	{
		if (empty($control_id)) {
			return;
		}

		$this->add_control(
			'tp_' . $control_id . '_icon_type',
			[
				'label' => esc_html__('Select Icon Type', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::SELECT,
				'default' => 'icon',
				'options' => [
					'image' => esc_html__('Image', 'unlock-addons-for-elementor'),
					'icon' => esc_html__('Icon', 'unlock-addons-for-elementor'),
					'svg' => esc_html__('SVG', 'unlock-addons-for-elementor'),
				],
				'condition' => $condition_key ? [
					$condition_key => $conditions_value
				] : [],
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_image',
			[
				'label' => esc_html__('Upload Icon Image', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'default' => [
					'url' => \Elementor\Utils::get_placeholder_image_src(),
				],
				'condition' => $condition_key ? [
					'tp_' . $control_id . '_icon_type' => 'image',
					$condition_key => $conditions_value
				] : [
					'tp_' . $control_id . '_icon_type' => 'image',
				],
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_icon_svg',
			[
				'show_label' => false,
				'type' => \Elementor\Controls_Manager::TEXTAREA,
				'label_block' => true,
				'placeholder' => esc_html__('SVG Code Here', 'unlock-addons-for-elementor'),
				'condition' => $condition_key ? [
					'tp_' . $control_id . '_icon_type' => 'svg',
					$condition_key => $conditions_value
				] : [
					'tp_' . $control_id . '_icon_type' => 'svg',
				],
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_icon',
			[
				'label' => esc_html__('Icon', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::ICONS,
				'default' => [
					'value' => 'fa-regular fa-arrow-right',
					'library' => 'fa-solid',
				],
				'condition' => $condition_key ? [
					'tp_' . $control_id . '_icon_type' => 'icon',
					$condition_key => $conditions_value
				] : [
					'tp_' . $control_id . '_icon_type' => 'icon',
				],
			]
		);
	}

	/**
	 * Section style controls
	 * 
	 * @since 1.0.0
	 * @param string $control_id
	 * @param string $control_name
	 * @param string $control_selector
	 */
	protected function tp_section_style_controls($control_id = null, $control_name = null, $control_selector = null)
	{
		if (empty($control_id) || empty($control_name) || empty($control_selector)) {
			return;
		}

		$this->start_controls_section(
			'tp_' . $control_id . '_area_styling',
			[
				'label' => esc_html__($control_name, 'unlock-addons-for-elementor'),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'tp_' . $control_id . 'area_background',
				'label' => esc_html__('Background', 'unlock-addons-for-elementor'),
				'types' => ['classic', 'gradient'],
				'selector' => '{{WRAPPER}} ' . $control_selector,
			]
		);

		$this->add_responsive_control(
			'tp_' . $control_id . '_area_padding',
			[
				'label' => esc_html__('Padding', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => ['px', '%', 'em'],
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
				],
				'separator' => 'before',
			]
		);

		$this->add_responsive_control(
			'tp_' . $control_id . '_area_margin',
			[
				'label' => esc_html__('Margin', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => ['px', '%', 'em'],
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
				],
				'separator' => 'before',
			]
		);

		$this->add_responsive_control(
			'tp_' . $control_id . '_area_border_radius',
			[
				'label' => esc_html__('Border Radius', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => ['px', '%', 'em'],
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
				],
				'separator' => 'before',
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Border::get_type(),
			[
				'name' => 'tp_' . $control_id . '_border',
				'label' => esc_html__('Border', 'unlock-addons-for-elementor'),
				'selector' => '{{WRAPPER}} ' . $control_selector,
			]
		);

		$this->end_controls_section();
	}

	/**
	 * Box controls style
	 * 
	 * @since 1.0.0
	 * @param string $control_id
	 * @param string $control_name
	 * @param string $control_selector
	 * @param array|null $condition
	 */
	protected function tp_box_controls_style($control_id = 'sec', $control_name = 'Button', $control_selector = '.tp-btn', $condition = null)
	{
		$section_args = [
			'label' => esc_html__($control_name, 'unlock-addons-for-elementor'),
			'tab' => \Elementor\Controls_Manager::TAB_STYLE,
		];

		if ($condition) {
			$section_args['condition'] = [
				'wpr_design_style' => $condition
			];
		}

		$this->start_controls_section(
			'tp_' . $control_id . '_button',
			$section_args
		);

		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			[
				'name' => 'tp_' . $control_id . '_typography',
				'selector' => '{{WRAPPER}} ' . $control_selector . '',
			]
		);

		$this->start_controls_tabs('tp_' . $control_id . '_button_tabs');

		// Normal State Tab
		$this->start_controls_tab('tp_' . $control_id . '_btn_normal', ['label' => esc_html__('Normal', 'unlock-addons-for-elementor')]);

		$this->add_control(
			'tp_' . $control_id . '_btn_normal_bg_color',
			[
				'label' => esc_html__('Background Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector . '' => 'background: {{VALUE}} !important;',
				],
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Box_Shadow::get_type(),
			[
				'name' => 'tp_' . $control_id . '_btn_box_shadow',
				'label' => esc_html__('Box Shadow', 'unlock-addons-for-elementor'),
				'selector' => '{{WRAPPER}} ' . $control_selector . '',
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Border::get_type(),
			[
				'name' => 'tp_' . $control_id . '_btn_normal_border_style',
				'selector' => '{{WRAPPER}} ' . $control_selector,
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_btn_normal_border_radius',
			[
				'label' => esc_html__('Border Radius', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => ['px', '%', 'em', 'rem'],
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);

		$this->end_controls_tab();

		// Hover State Tab
		$this->start_controls_tab('tp_' . $control_id . '_btn_hover', ['label' => esc_html__('Hover', 'unlock-addons-for-elementor')]);

		$this->add_control(
			'tp_' . $control_id . '_btn_hover_bg_color',
			[
				'label' => esc_html__('Background Color', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector . ':hover' => 'background: {{VALUE}} !important;',
				],
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Box_Shadow::get_type(),
			[
				'name' => 'tp_' . $control_id . '_btn_box_shadow_hover',
				'label' => esc_html__('Box Shadow', 'unlock-addons-for-elementor'),
				'selector' => '{{WRAPPER}} ' . $control_selector . ':hover',
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Border::get_type(),
			[
				'name' => 'tp_' . $control_id . '_btn_hover_border_style',
				'selector' => '{{WRAPPER}} ' . $control_selector . ':hover',
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_btn_hover_border_radius',
			[
				'label' => esc_html__('Border Radius', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => ['px', '%', 'em', 'rem'],
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector . ':hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);

		$this->end_controls_tab();
		$this->end_controls_tabs();

		$this->add_responsive_control(
			'tp_' . $control_id . '_padding',
			[
				'label' => esc_html__('Padding', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => ['px', 'em', '%'],
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector . '' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);

		$this->add_responsive_control(
			'tp_' . $control_id . '_margin',
			[
				'label' => esc_html__('Margin', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => ['px', 'em', '%'],
				'selectors' => [
					'{{WRAPPER}} ' . $control_selector . '' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);

		$this->end_controls_section();
	}

	/**
	 * Query controls for post queries
	 * 
	 * @since 1.0.0
	 */
	protected function tp_query_controls($control_id = null, $control_name = null, $post_type = 'any', $taxonomy = 'category', $default_title_num = 6, $default_content_limit = '10', $posts_per_page = '6', $offset = '0', $orderby = 'date', $order = 'desc', $date_format = false, $has_content = false, $view_pagination = false, $post_read_more = false)
	{
		$this->start_controls_section(
			'tp' . $control_id . '_query',
			[
				'label' => sprintf(esc_html__('%s Query', 'unlock-addons-for-elementor'), $control_name),
			]
		);

		$this->add_control(
			'posts_per_page',
			[
				'label' => esc_html__('Posts Per Page', 'unlock-addons-for-elementor'),
				'description' => esc_html__('Leave blank or enter -1 for all.', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::NUMBER,
				'default' => $posts_per_page,
			]
		);

		$this->add_control(
			'category',
			[
				'label' => esc_html__('Include Categories', 'unlock-addons-for-elementor'),
				'description' => esc_html__('Select a category to include or leave blank for all.', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT2,
				'multiple' => true,
				'options' => $this->tp_get_categories($taxonomy),
				'label_block' => true,
			]
		);

		$this->add_control(
			'exclude_category',
			[
				'label' => esc_html__('Exclude Categories', 'unlock-addons-for-elementor'),
				'description' => esc_html__('Select a category to exclude', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT2,
				'multiple' => true,
				'options' => $this->tp_get_categories($taxonomy),
				'label_block' => true
			]
		);

		$this->add_control(
			'post__not_in',
			[
				'label' => esc_html__('Exclude Item', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT2,
				'options' => $this->tp_get_all_types_post($post_type),
				'multiple' => true,
				'label_block' => true
			]
		);

		$this->add_control(
			'post__in',
			[
				'label' => esc_html__('Include Item', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT2,
				'options' => $this->tp_get_all_types_post($post_type),
				'multiple' => true,
				'label_block' => true
			]
		);

		$this->add_control(
			'offset',
			[
				'label' => esc_html__('Offset', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::NUMBER,
				'default' => $offset,
			]
		);

		$this->add_control(
			'orderby',
			[
				'label' => esc_html__('Order By', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => $this->tp_get_orderby_options(),
				'default' => $orderby,
			]
		);

		$this->add_control(
			'order',
			[
				'label' => esc_html__('Order', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => [
					'asc' => esc_html__('Ascending', 'unlock-addons-for-elementor'),
					'desc' => esc_html__('Descending', 'unlock-addons-for-elementor')
				],
				'default' => $order,
			]
		);

		$this->add_control(
			'ignore_sticky_posts',
			[
				'label' => esc_html__('Ignore Sticky Posts', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => esc_html__('Yes', 'unlock-addons-for-elementor'),
				'label_off' => esc_html__('No', 'unlock-addons-for-elementor'),
				'return_value' => 'yes',
				'default' => 'yes',
			]
		);

		$this->add_control(
			'tp_post_title_word',
			[
				'label' => esc_html__('Title Word Count', 'unlock-addons-for-elementor'),
				'description' => esc_html__('Set how many word you want to display!', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::NUMBER,
				'default' => $default_title_num,
			]
		);

		if ($date_format) {
			$this->add_control(
				'tp_post_date_format',
				[
					'label' => esc_html__('Date Format', 'unlock-addons-for-elementor'),
					'type' => \Elementor\Controls_Manager::SELECT,
					'options' => [
						'default' => esc_html__('Default', 'unlock-addons-for-elementor'),
						'd-m-Y' => esc_html__('d-m-Y', 'unlock-addons-for-elementor'),
						'd/m/Y' => esc_html__('d/m/Y', 'unlock-addons-for-elementor'),
						'm-d-Y' => esc_html__('m-d-Y', 'unlock-addons-for-elementor'),
						'm/d/Y' => esc_html__('m/d/Y', 'unlock-addons-for-elementor'),
						'Y-m-d' => esc_html__('Y-m-d', 'unlock-addons-for-elementor'),
						'custom' => esc_html__('Custom', 'unlock-addons-for-elementor'),
					],
					'default' => 'default',
				]
			);

			$this->add_control(
				'tp_post_date_custom_format',
				[
					'label' => esc_html__('Custom Date Format', 'unlock-addons-for-elementor'),
					'description' => esc_html__('Enter your custom date format.', 'unlock-addons-for-elementor'),
					'type' => Controls_Manager::TEXT,
					'default' => 'F j, Y',
					'condition' => [
						'tp_post_date_format' => 'custom',
					]
				]
			);
		}

		if ($post_type == 'post' && $has_content) {
			$this->add_control(
				'tp_post_content',
				[
					'label' => __('Content', 'unlock-addons-for-elementor'),
					'type' => Controls_Manager::SWITCHER,
					'label_on' => __('Show', 'unlock-addons-for-elementor'),
					'label_off' => __('Hide', 'unlock-addons-for-elementor'),
					'return_value' => 'yes',
					'default' => 'yes',
				]
			);

			$this->add_control(
				'tp_post_content_limit',
				[
					'label' => __('Content Limit', 'unlock-addons-for-elementor'),
					'type' => Controls_Manager::TEXT,
					'default' => $default_content_limit,
					'dynamic' => [
						'active' => true,
					],
					'condition' => [
						'tp_post_content' => 'yes',
					]
				]
			);
		}

		$this->end_controls_section();
	}

	/**
	 * Query meta controls
	 * 
	 * @since 1.0.0
	 */
	protected function tp_query_meta_controls($control_id = null, $control_name = null, $show_category = true, $show_date = true, $show_reading_time = true, $show_author = true, $show_comment = false)
	{
		$this->start_controls_section(
			'tp' . $control_id . '_meta',
			[
				'label' => sprintf(esc_html__('%s Meta', 'unlock-addons-for-elementor'), $control_name),
			]
		);

		if ($show_category) {
			$this->add_control(
				'tp_post_category',
				[
					'label' => esc_html__('Category', 'unlock-addons-for-elementor'),
					'type' => Controls_Manager::SWITCHER,
					'label_on' => esc_html__('Show', 'unlock-addons-for-elementor'),
					'label_off' => esc_html__('Hide', 'unlock-addons-for-elementor'),
					'return_value' => 'yes',
					'default' => 'yes',
				]
			);
		}

		if ($show_date) {
			$this->add_control(
				'tp_post_date',
				[
					'label' => esc_html__('Date', 'unlock-addons-for-elementor'),
					'type' => Controls_Manager::SWITCHER,
					'label_on' => esc_html__('Show', 'unlock-addons-for-elementor'),
					'label_off' => esc_html__('Hide', 'unlock-addons-for-elementor'),
					'return_value' => 'yes',
					'default' => 'yes',
				]
			);
		}

		if ($show_reading_time) {
			$this->add_control(
				'tp_post_reading_time',
				[
					'label' => esc_html__('Reading Time', 'unlock-addons-for-elementor'),
					'type' => Controls_Manager::SWITCHER,
					'label_on' => esc_html__('Show', 'unlock-addons-for-elementor'),
					'label_off' => esc_html__('Hide', 'unlock-addons-for-elementor'),
					'return_value' => 'yes',
					'default' => 'yes',
				]
			);
		}

		if ($show_author) {
			$this->add_control(
				'tp_post_author',
				[
					'label' => esc_html__('Author', 'unlock-addons-for-elementor'),
					'type' => Controls_Manager::SWITCHER,
					'label_on' => esc_html__('Show', 'unlock-addons-for-elementor'),
					'label_off' => esc_html__('Hide', 'unlock-addons-for-elementor'),
					'return_value' => 'yes',
					'default' => 'no',
				]
			);
		}

		if ($show_comment) {
			$this->add_control(
				'tp_post_comment',
				[
					'label' => esc_html__('Comment', 'unlock-addons-for-elementor'),
					'type' => Controls_Manager::SWITCHER,
					'label_on' => esc_html__('Show', 'unlock-addons-for-elementor'),
					'label_off' => esc_html__('Hide', 'unlock-addons-for-elementor'),
					'return_value' => 'yes',
					'default' => 'no',
				]
			);
		}

		$this->end_controls_section();
	}

	/**
	 * Column controls
	 * 
	 * @since 1.0.0
	 */
	protected function tp_columns($control_id = 'columns_options', $condition = null, $control_name = 'Select Columns', $default_for_lg = '4', $default_for_md = '6', $default_for_sm = '6', $default_for_all = '12')
	{
		$section_args = [
			'label' => esc_html__($control_name, 'unlock-addons-for-elementor'),
		];

		if ($condition) {
			$section_args['condition'] = [
				'wpr_design_style' => $condition
			];
		}

		$this->start_controls_section(
			'tp_' . $control_id . 'columns_section',
			$section_args
		);

		$this->add_control(
			'tp_' . $control_id . '_for_desktop',
			[
				'label' => esc_html__('Columns for Desktop', 'unlock-addons-for-elementor'),
				'description' => esc_html__('Screen width equal to or greater than 1200px', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => [
					12 => esc_html__('1 Columns', 'unlock-addons-for-elementor'),
					6 => esc_html__('2 Columns', 'unlock-addons-for-elementor'),
					4 => esc_html__('3 Columns', 'unlock-addons-for-elementor'),
					3 => esc_html__('4 Columns', 'unlock-addons-for-elementor'),
					2 => esc_html__('6 Columns', 'unlock-addons-for-elementor'),
				],
				'separator' => 'before',
				'default' => $default_for_lg,
				'style_transfer' => true,
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_for_laptop',
			[
				'label' => esc_html__('Columns for Large', 'unlock-addons-for-elementor'),
				'description' => esc_html__('Screen width equal to or greater than 992px', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => [
					12 => esc_html__('1 Columns', 'unlock-addons-for-elementor'),
					6 => esc_html__('2 Columns', 'unlock-addons-for-elementor'),
					4 => esc_html__('3 Columns', 'unlock-addons-for-elementor'),
					3 => esc_html__('4 Columns', 'unlock-addons-for-elementor'),
					2 => esc_html__('6 Columns', 'unlock-addons-for-elementor'),
				],
				'separator' => 'before',
				'default' => $default_for_md,
				'style_transfer' => true,
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_for_tablet',
			[
				'label' => esc_html__('Columns for Tablet', 'unlock-addons-for-elementor'),
				'description' => esc_html__('Screen width equal to or greater than 768px', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => [
					12 => esc_html__('1 Columns', 'unlock-addons-for-elementor'),
					6 => esc_html__('2 Columns', 'unlock-addons-for-elementor'),
					4 => esc_html__('3 Columns', 'unlock-addons-for-elementor'),
					3 => esc_html__('4 Columns', 'unlock-addons-for-elementor'),
					2 => esc_html__('6 Columns', 'unlock-addons-for-elementor'),
				],
				'separator' => 'before',
				'default' => $default_for_sm,
				'style_transfer' => true,
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_for_mobile',
			[
				'label' => esc_html__('Columns for Mobile', 'unlock-addons-for-elementor'),
				'description' => esc_html__('Screen width less than 767px', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => [
					12 => esc_html__('1 Columns', 'unlock-addons-for-elementor'),
					6 => esc_html__('2 Columns', 'unlock-addons-for-elementor'),
					4 => esc_html__('3 Columns', 'unlock-addons-for-elementor'),
					3 => esc_html__('4 Columns', 'unlock-addons-for-elementor'),
					2 => esc_html__('6 Columns', 'unlock-addons-for-elementor'),
				],
				'separator' => 'before',
				'default' => $default_for_all,
				'style_transfer' => true,
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_for_xs',
			[
				'label' => esc_html__('Columns for XS Devices', 'unlock-addons-for-elementor'),
				'description' => esc_html__('Screen width less than 767px', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => [
					12 => esc_html__('1 Columns', 'unlock-addons-for-elementor'),
					6 => esc_html__('2 Columns', 'unlock-addons-for-elementor'),
					4 => esc_html__('3 Columns', 'unlock-addons-for-elementor'),
					3 => esc_html__('4 Columns', 'unlock-addons-for-elementor'),
					2 => esc_html__('6 Columns', 'unlock-addons-for-elementor'),
				],
				'separator' => 'before',
				'default' => $default_for_all,
				'style_transfer' => true,
			]
		);

		$this->end_controls_section();
	}

	/**
	 * Column show helper
	 * 
	 * @since 1.0.0
	 */
	protected function col_show($data, $key = 'col')
	{
		$desktop = "col-xl-" . esc_attr($data['tp_' . $key . '_for_desktop']);
		$laptop = "col-lg-" . esc_attr($data['tp_' . $key . '_for_laptop']);
		$tablet = "col-md-" . esc_attr($data['tp_' . $key . '_for_tablet']);
		$mobile = "col-sm-" . esc_attr($data['tp_' . $key . '_for_mobile']);
		$xs = "col-" . esc_attr($data['tp_' . $key . '_for_xs']);

		$total_col = $desktop . " " . $laptop . " " . $tablet . " " . $mobile . " " . $xs;

		return $total_col;
	}

	/**
	 * Creative animation controls
	 * 
	 * @since 1.0.0
	 */
	protected function tp_creative_animation($condition = null, $control_id = 'ani_demo', $style = 'wpr_design_style', $control_name = 'Creative Animation')
	{
		$section_args = [
			'label' => esc_html__($control_name, 'unlock-addons-for-elementor'),
			'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
		];

		if ($condition) {
			$section_args['condition'] = [
				$style => $condition
			];
		}

		$this->start_controls_section(
			'creative_animation_sec',
			$section_args
		);

		$this->add_control(
			'tp_creative_anima_switcher',
			[
				'label' => esc_html__('Active Animation', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'label_on' => esc_html__('Yes', 'unlock-addons-for-elementor'),
				'label_off' => esc_html__('No', 'unlock-addons-for-elementor'),
				'return_value' => 'yes',
				'default' => '0',
				'separator' => 'before',
			]
		);

		$this->add_control(
			'tp_anima_type',
			[
				'label' => __('Animation Type', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => [
					'fadeIn' => __('fadeIn', 'unlock-addons-for-elementor'),
					'fadeInUp' => __('fadeInUp', 'unlock-addons-for-elementor'),
					'fadeInDown' => __('fadeInDown', 'unlock-addons-for-elementor'),
					'fadeInLeft' => __('fadeInLeft', 'unlock-addons-for-elementor'),
					'fadeInRight' => __('fadeInRight', 'unlock-addons-for-elementor'),
					'bounceIn' => __('bounceIn', 'unlock-addons-for-elementor'),
				],
				'default' => 'fadeInUp',
				'frontend_available' => true,
				'style_transfer' => true,
				'condition' => [
					'tp_creative_anima_switcher' => 'yes',
				],
			]
		);

		$this->add_control(
			'tp_anima_dura',
			[
				'label' => esc_html__('Animation Duration', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::TEXT,
				'default' => esc_html__('0.3s', 'unlock-addons-for-elementor'),
				'condition' => [
					'tp_creative_anima_switcher' => 'yes',
				],
			]
		);

		$this->add_control(
			'tp_anima_delay',
			[
				'label' => esc_html__('Animation Delay', 'unlock-addons-for-elementor'),
				'type' => \Elementor\Controls_Manager::TEXT,
				'default' => esc_html__('0.3s', 'unlock-addons-for-elementor'),
				'condition' => [
					'tp_creative_anima_switcher' => 'yes',
				],
			]
		);

		$this->end_controls_section();
	}

	/**
	 * Render links controls helper
	 * 
	 * @since 1.0.0
	 */
	protected function tp_render_links_controls($control_id = 'link')
	{
		$this->add_control(
			'tp_' . $control_id . '_link_type',
			[
				'label' => esc_html__(' Link Type', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => [
					'1' => 'Custom Link',
					'2' => 'Internal Page',
				],
				'default' => '1',
				'label_block' => true,
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_link',
			[
				'label' => esc_html__('Link', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::URL,
				'dynamic' => [
					'active' => true,
				],
				'placeholder' => esc_html__('https://your-link.com', 'unlock-addons-for-elementor'),
				'show_external' => false,
				'default' => [
					'url' => '#',
					'is_external' => false,
					'nofollow' => false,
				],
				'condition' => [
					'tp_' . $control_id . '_link_type' => '1',
				],
				'label_block' => true,
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_page_link',
			[
				'label' => esc_html__('Select Page', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT2,
				'label_block' => true,
				'options' => $this->tp_get_all_types_post('page'),
				'condition' => [
					'tp_' . $control_id . '_link_type' => '2',
				]
			]
		);
	}

	/**
	 * Animation show helper
	 * 
	 * @since 1.0.0
	 */
	protected function tp_animation_show($data)
	{
		$animation = !empty($data['tp_creative_anima_switcher']) && $data['tp_creative_anima_switcher'] == 'yes' ? 'wow ' . $data['tp_anima_type'] : NULL;
		$duration = !empty($data['tp_anima_dura']) ? 'data-wow-duration="' . $data['tp_anima_dura'] . '"' : NULL;
		$delay = !empty($data['tp_anima_delay']) ? 'data-wow-delay="' . $data['tp_anima_delay'] . '"' : NULL;

		return [
			'animation' => $animation,
			'duration' => $duration,
			'delay' => $delay,
		];
	}

	/**
	 * Link render controls with button show/hide
	 * 
	 * @since 1.0.0
	 * @param string $control_id Control ID
	 * @param string $control_name Control name
	 * @param array|null $control_condition Condition for layout
	 * @param string $default_btn_text Default button text
	 * @param string $default_btn_enable Default button enable state
	 */
	protected function tp_link_render_controls($control_id = 'button', $control_name = 'Button', $control_condition = null, $default_btn_text = 'Read More', $default_btn_enable = 'yes')
	{
		if ($control_condition) {
			$this->start_controls_section(
				'tp_' . $control_id . '_button_group',
				[
					'label' => esc_html__($control_name, 'unlock-addons-for-elementor'),
					'condition' => [
						'wpr_design_style' => $control_condition
					],
				]
			);
		} else {
			$this->start_controls_section(
				'tp_' . $control_id . '_button_group',
				[
					'label' => esc_html__($control_name, 'unlock-addons-for-elementor'),
				]
			);
		}

		$this->add_control(
			'tp_' . $control_id . '_button_show',
			[
				'label' => esc_html__('Show Button', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => esc_html__('Show', 'unlock-addons-for-elementor'),
				'label_off' => esc_html__('Hide', 'unlock-addons-for-elementor'),
				'return_value' => 'yes',
				'default' => $default_btn_enable,
			]
		);

		$this->add_control(
			'tp_' . $control_id . '_text',
			[
				'label' => esc_html__($control_name . ' Text', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::TEXT,
				'default' => $default_btn_text,
				'title' => esc_html__('Enter button text', 'unlock-addons-for-elementor'),
				'label_block' => true,
				'condition' => [
					'tp_' . $control_id . '_button_show' => 'yes'
				],
			]
		);
		$this->add_control(
			'tp_' . $control_id . '_link_type',
			[
				'label' => esc_html__($control_name . ' Link Type', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'options' => [
					'1' => 'Custom Link',
					'2' => 'Internal Page',
				],
				'default' => '1',
				'label_block' => true,
				'condition' => [
					'tp_' . $control_id . '_button_show' => 'yes'
				],
			]
		);
		$this->add_control(
			'tp_' . $control_id . '_link',
			[
				'label' => esc_html__($control_name . ' link', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::URL,
				'dynamic' => [
					'active' => true,
				],
				'placeholder' => esc_html__('https://your-link.com', 'unlock-addons-for-elementor'),
				'show_external' => false,
				'default' => [
					'url' => '#',
					'is_external' => false,
					'nofollow' => false,
				],
				'condition' => [
					'tp_' . $control_id . '_link_type' => '1',
					'tp_' . $control_id . '_button_show' => 'yes'
				],
				'label_block' => true,
			]
		);
		$this->add_control(
			'tp_' . $control_id . '_page_link',
			[
				'label' => esc_html__('Select ' . $control_name . ' Page', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT2,
				'label_block' => true,
				'options' => $this->tp_get_all_types_post('page'),
				'condition' => [
					'tp_' . $control_id . '_link_type' => '2',
					'tp_' . $control_id . '_button_show' => 'yes'
				]
			]
		);
		$this->end_controls_section();
	}

	/**
	 * Render icon controls
	 * 
	 * @since 1.0.0
	 * @param object|null $settings Settings object (usually $this or $repeater)
	 * @param string $key Control key
	 */
	protected function tp_render_icon_controls($settings = null, $key = 'icon')
	{
		$settings->add_control(
			'tp_' . $key . '_icon_type',
			[
				'label' => esc_html__('Select Icon Type', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::SELECT,
				'default' => 'icon',
				'options' => [
					'image' => esc_html__('Image', 'unlock-addons-for-elementor'),
					'icon' => esc_html__('Icon', 'unlock-addons-for-elementor'),
					'svg' => esc_html__('SVG', 'unlock-addons-for-elementor'),
				],
			]
		);
		$settings->add_control(
			'tp_' . $key . '_icon_svg',
			[
				'show_label' => false,
				'type' => Controls_Manager::TEXTAREA,
				'label_block' => true,
				'placeholder' => esc_html__('SVG Code Here', 'unlock-addons-for-elementor'),
				'condition' => [
					'tp_' . $key . '_icon_type' => 'svg',
				]
			]
		);

		$settings->add_control(
			'tp_' . $key . '_image',
			[
				'label' => esc_html__('Upload Icon Image', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::MEDIA,
				'default' => [
					'url' => \Elementor\Utils::get_placeholder_image_src(),
				],
				'condition' => [
					'tp_' . $key . '_icon_type' => 'image',
				]
			]
		);


		$settings->add_control(
			'tp_' . $key . '_icon',
			[
				'label' => esc_html__('Icon', 'unlock-addons-for-elementor'),
				'type' => Controls_Manager::ICONS,
				'default' => [
					'value' => 'fab fa-facebook',
					'library' => 'fa-brands',
				],
				'condition' => [
					'tp_' . $key . '_icon_type' => 'icon',
				],
			]
		);
	}
}
