<?php

namespace MasterAddons\Addons;

use MasterAddons\Inc\Classes\Base\Master_Widget;
use \Elementor\Controls_Manager;
use \Elementor\Repeater;
use \Elementor\Utils;
use \Elementor\Group_Control_Border;
use \Elementor\Group_Control_Typography;
use \Elementor\Group_Control_Image_Size;

use MasterAddons\Inc\Controls\Group\JLTMA_Transition;
use MasterAddons\Inc\Traits\JLTMA_Swiper_Controls;
use MasterAddons\Inc\Classes\Helper;
use MasterAddons\Inc\Admin\Config;

if (!defined('ABSPATH'))
	exit; // If this file is called directly, abort.

class Team_Slider extends Master_Widget
{
	use \MasterAddons\Inc\Traits\Widget_Notice;
	use \MasterAddons\Inc\Traits\Widget_Assets_Trait;

	use JLTMA_Swiper_Controls;
	public function get_name()
	{
		return 'ma-team-members-slider';
	}

	public function get_title()
	{
		return esc_html__('Team Slider', 'master-addons');
	}

	public function get_icon()
	{
		return 'jltma-icon ' . Config::get_addon_icon($this->get_name());
	}

	public function get_keywords()
	{
		return [
			'team',
			'members',
			'carousel',
			'slider',
			'team members',
			'team scroll',
			'team members slider',
			'person slider'
		];
	}

	public function has_widget_inner_wrapper(): bool
	{
		return false;
	}

	protected function register_controls()
	{

		$this->start_controls_section(
			'section_team_carousel',
			[
				'label' => esc_html__('Contents', 'master-addons'),
			]
		);

		// Define default free options - Pro version overrides via filter
		$carousel_preset_options = apply_filters('master_addons/addons/team_slider/preset', [
			'-default'            => __('Team Carousel', 'master-addons'),
			'-circle'             => __('Circle Gradient', 'master-addons'),
			'-content-hover'      => __('Content on Hover', 'master-addons'),
			'-pro-team-slider-1'  => __('Social Left on Hover (Pro)', 'master-addons'),
			'-pro-team-slider-2'  => __('Content Drawer (Pro)', 'master-addons'),
			'-pro-team-slider-3'  => __('Circle Animation (Pro)', 'master-addons'),
		]);

		$this->add_control(
			'ma_el_team_carousel_preset',
			[
				'label'              => esc_html__('Style Preset', 'master-addons'),
				'type'               => Controls_Manager::SELECT,
				'default'            => '-default',
				'options'            => $carousel_preset_options,
				'frontend_available' => true,
				'description'        => Helper::upgrade_to_pro('3+ more Variations on'),
			]
		);

		// Circle image options - Pro version overrides via filter
		$circle_image_options = apply_filters('master_addons/addons/team_slider/circle_image', [
			'circle_01'    => esc_html__('Circle 01', 'master-addons'),
			'circle_02'    => esc_html__('Circle 02', 'master-addons'),
			'circle_03'    => esc_html__('Circle 03', 'master-addons'),
			'circle-pro-1' => esc_html__('Circle 04 (Pro)', 'master-addons'),
			'circle-pro-2' => esc_html__('Circle 05 (Pro)', 'master-addons'),
			'circle-pro-3' => esc_html__('Circle 06 (Pro)', 'master-addons'),
			'circle-pro-4' => esc_html__('Circle 07 (Pro)', 'master-addons'),
		]);

		$this->add_control(
			'ma_el_team_circle_image',
			[
				'label'       => esc_html__('Circle Gradient Image', 'master-addons'),
				'type'        => Controls_Manager::SELECT,
				'default'     => 'circle_01',
				'options'     => $circle_image_options,
				'condition'   => [
					'ma_el_team_carousel_preset' => '-circle'
				],
				'description' => Helper::upgrade_to_pro('4+ more Circle Variations on'),
			]
		);

		// Animation style options - Pro version overrides via filter
		$animation_style_options = apply_filters('master_addons/addons/team_slider/animation_style', [
			'animation_svg_01'   => esc_html__('Animation 1', 'master-addons'),
			'animation_svg_02'   => esc_html__('Animation 2', 'master-addons'),
			'animation_svg_03'   => esc_html__('Animation 3', 'master-addons'),
			'svg_animated_pro_1' => esc_html__('Animation 4 (Pro)', 'master-addons'),
		]);

		$this->add_control(
			'ma_el_team_circle_image_animation',
			[
				'label'       => esc_html__('Animation Style', 'master-addons'),
				'type'        => Controls_Manager::SELECT,
				'default'     => 'animation_svg_01',
				'options'     => $animation_style_options,
				'condition'   => [
					'ma_el_team_carousel_preset' => '-circle-animation'
				],
				'description' => Helper::upgrade_to_pro('More Animated Variations on'),
			]
		);

		$team_repeater = new Repeater();

		/*
		 * Team Member Image
		 */
		$team_repeater->add_control(
			'ma_el_team_carousel_image',
			[
				'label' => __('Image', 'master-addons'),
				'type' => Controls_Manager::MEDIA,
				'default' => [
					'url' => Utils::get_placeholder_image_src(),
				],
				'selectors' => [
					// '{{WRAPPER}} .jltma-team-member-circle-animation .jltma-team-member-thumb .animation_svg_02:after' => 'background-image: url("{{URL}}");'
				]

			]
		);
		$team_repeater->add_control(
			'ma_el_team_carousel_name',
			[
				'label' => esc_html__('Name', 'master-addons'),
				'type' => Controls_Manager::TEXT,
				'label_block' => true,
				'default' => esc_html__('John Doe', 'master-addons'),
			]
		);

		$team_repeater->add_control(
			'ma_el_team_carousel_designation',
			[
				'label' => esc_html__('Designation', 'master-addons'),
				'type' => Controls_Manager::TEXT,
				'label_block' => true,
				'default' => esc_html__('My Designation', 'master-addons'),
			]
		);

		$team_repeater->add_control(
			'ma_el_team_carousel_description',
			[
				'label' => esc_html__('Description', 'master-addons'),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__('Add team member details here', 'master-addons'),
			]
		);

		$team_repeater->add_control(
			'ma_el_team_carousel_enable_social_profiles',
			[
				'label' => esc_html__('Display Social Profiles?', 'master-addons'),
				'type' => Controls_Manager::SWITCHER,
				'default' => 'yes',
			]
		);

		$team_repeater->add_control(
			'ma_el_team_carousel_facebook_link',
			[
				'label' => __('Facebook URL', 'master-addons'),
				'type' => Controls_Manager::URL,
				'condition' => [
					'ma_el_team_carousel_enable_social_profiles!' => '',
				],
				'placeholder' => __('https://master-addons.com', 'master-addons'),
				'label_block' => true,
				'default' => [
					'url' => '',
					'is_external' => true,
				],
			]
		);

		$team_repeater->add_control(
			'ma_el_team_carousel_twitter_link',
			[
				'label' => __('Twitter URL', 'master-addons'),
				'type' => Controls_Manager::URL,
				'condition' => [
					'ma_el_team_carousel_enable_social_profiles!' => '',
				],
				'placeholder' => __('https://master-addons.com', 'master-addons'),
				'label_block' => true,
				'default' => [
					'url' => '',
					'is_external' => true,
				],
			]
		);

		$team_repeater->add_control(
			'ma_el_team_carousel_instagram_link',
			[
				'label' => __('Instagram URL', 'master-addons'),
				'type' => Controls_Manager::URL,
				'condition' => [
					'ma_el_team_carousel_enable_social_profiles!' => '',
				],
				'placeholder' => __('https://master-addons.com', 'master-addons'),
				'label_block' => true,
				'default' => [
					'url' => '',
					'is_external' => true,
				],
			]
		);

		$team_repeater->add_control(
			'ma_el_team_carousel_linkedin_link',
			[
				'label' => __('Linkedin URL', 'master-addons'),
				'type' => Controls_Manager::URL,
				'condition' => [
					'ma_el_team_carousel_enable_social_profiles!' => '',
				],
				'placeholder' => __('https://master-addons.com', 'master-addons'),
				'label_block' => true,
				'default' => [
					'url' => '',
					'is_external' => true,
				],
			]
		);

		$team_repeater->add_control(
			'ma_el_team_carousel_dribbble_link',
			[
				'label' => __('Dribbble URL', 'master-addons'),
				'type' => Controls_Manager::URL,
				'condition' => [
					'ma_el_team_carousel_enable_social_profiles!' => '',
				],
				'placeholder' => __('https://master-addons.com', 'master-addons'),
				'label_block' => true,
				'default' => [
					'url' => '',
					'is_external' => true,
				],
			]
		);
		$team_repeater->add_control(
			'ma_el_team_carousel_tiktok_link',
			[
				'label' => __('Tiktok URL', 'master-addons'),
				'type' => Controls_Manager::URL,
				'condition' => [
					'ma_el_team_carousel_enable_social_profiles!' => '',
				],
				'placeholder' => __('https://master-addons.com', 'master-addons'),
				'label_block' => true,
				'default' => [
					'url' => '',
					'is_external' => true,
				],
			]
		);
		$team_repeater->add_control(
			'ma_el_team_carousel_youtube_link',
			[
				'label' => __('Youtube URL', 'master-addons'),
				'type' => Controls_Manager::URL,
				'condition' => [
					'ma_el_team_carousel_enable_social_profiles!' => '',
				],
				'placeholder' => __('https://master-addons.com', 'master-addons'),
				'label_block' => true,
				'default' => [
					'url' => '',
					'is_external' => true,
				],
			]
		);
		$team_repeater->add_control(
			'ma_el_team_carousel_email_link',
			[
				'label' => __('Email', 'master-addons'),
				'type' => Controls_Manager::TEXT,
				'condition' => [
					'ma_el_team_carousel_enable_social_profiles!' => '',
				],
				'placeholder' => __('hello@master-addons.com', 'master-addons'),
				'label_block' => true,
				'default' => '',
			]
		);

		$this->add_control(
			'team_carousel_repeater',
			[
				'label' => esc_html__('Team Carousel', 'master-addons'),
				'type' => Controls_Manager::REPEATER,
				'fields' => $team_repeater->get_controls(),
				'title_field' => '{{{ ma_el_team_carousel_name }}}',
				'default' => [
					[
						'ma_el_team_carousel_name' => __('Team Member #1', 'master-addons'),
						'ma_el_team_carousel_description' => __('Add team member details here', 'master-addons'),
					],
					[
						'ma_el_team_carousel_name' => __('Team Member #2', 'master-addons'),
						'ma_el_team_carousel_description' => __('Add team member details here', 'master-addons'),
					],
					[
						'ma_el_team_carousel_name' => __('Team Member #3', 'master-addons'),
						'ma_el_team_carousel_description' => __('Add team member details here', 'master-addons'),
					],
					[
						'ma_el_team_carousel_name' => __('Team Member #4', 'master-addons'),
						'ma_el_team_carousel_description' => __('Add team member details here', 'master-addons'),
					],
				]
			]
		);

		$this->add_group_control(
			Group_Control_Image_Size::get_type(),
			[
				'name' => 'thumbnail',
				'default' => 'full'
			]
		);
		$this->add_control(
			'team_carousel_image_border_switch',
			[
				'label' => esc_html__('Image Border?', 'master-addons'),
				'type' => Controls_Manager::SWITCHER,
				'default' => 'no',
			]
		);
		$this->add_control(
			'team_carousel_image_border_radius',
			[
				'label' => esc_html__('Border Radius', 'master-addons'),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => ['px', 'em', '%'],
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-thumb img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
				'default' => [
					'top' => 60,
					'right' => 60,
					'bottom' => 60,
					'left' => 60,
					'unit' => 'px'
				],
				'condition' => [
					'team_carousel_image_border_switch' => 'yes'
				]
			]
		);

		$this->add_control(
			'title_html_tag',
			[
				'label' => __('Title HTML Tag', 'master-addons'),
				'type' => Controls_Manager::SELECT,
				'options' => Helper::jltma_title_tags(),
				'default' => 'h3',
			]
		);

		$this->end_controls_section();

		/*
		 * Team Members Styling Section
		 */
		$this->start_controls_section(
			'ma_el_section_team_carousel_styles_preset',
			[
				'label' => esc_html__('General Styles', 'master-addons'),
				'tab' => Controls_Manager::TAB_STYLE
			]
		);

		$this->add_responsive_control(
			'ma_el_team_image_bg_size',
			[
				'label' => __('Background Image Size', 'master-addons'),
				'description' => __('Height Width will be same ratio', 'master-addons'),
				'type' => Controls_Manager::SLIDER,
				'size_units' => ['px'],
				'range' => [
					'px' => [
						'min' => 100,
						'max' => 1000,
						'step' => 5,
					]
				],
				'default' => [
					'unit' => 'px',
					'size' => 125,
				],
				'condition' => [
					'ma_el_team_carousel_preset' => ['-circle', '-circle-animation']
				],
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-circle .jltma-team-member-thumb svg,
						{{WRAPPER}} .jltma-team-member-circle .jltma-team-member-thumb,
						{{WRAPPER}} .jltma-team-member-circle-animation .jltma-team-member-thumb svg,
						{{WRAPPER}} .jltma-team-member-circle-animation .jltma-team-member-thumb .animation_svg_02,
						{{WRAPPER}} .jltma-team-member-circle-animation .jltma-team-member-thumb .animation_svg_03,
						{{WRAPPER}} .jltma-team-member-circle-animation .jltma-team-member-thumb' =>
						'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};'

				]
			]
		);

		$this->add_responsive_control(
			'ma_el_team_image_bg_position_left',
			[
				'label' => __('Background Position(Left)', 'master-addons'),
				'type' => Controls_Manager::SLIDER,
				'size_units' => ['px', '%', 'em'],
				'default' => [
					'unit' => 'px',
					'size' => -5,
				],
				'range' => [
					'px' => [
						'min' => -100,
						'max' => 150,
						'step' => 1,
					]
				],
				'condition' => [
					'ma_el_team_carousel_preset' => ['-circle', '-circle-animation']
				],
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-circle .jltma-team-member-thumb svg,
						{{WRAPPER}} .jltma-team-member-circle-animation .jltma-team-member-thumb svg' => 'left: {{SIZE}}{{UNIT}};'
				]
			]
		);

		$this->add_responsive_control(
			'ma_el_team_image_bg_position_top',
			[
				'label' => __('Background Position(Top)', 'master-addons'),
				'type' => Controls_Manager::SLIDER,
				'size_units' => ['px', '%', 'em'],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 150,
						'step' => 1,
					]
				],
				'condition' => [
					'ma_el_team_carousel_preset' => ['-circle', '-circle-animation']
				],
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-circle .jltma-team-member-thumb svg,
						{{WRAPPER}} .jltma-team-member-circle-animation .jltma-team-member-thumb svg' => 'top: {{SIZE}}{{UNIT}};'
				]
			]
		);

		$this->add_responsive_control(
			'ma_el_team_image_size',
			[
				'label' => __('Member Image Size', 'master-addons'),
				'description' => __('Height Width will be same ratio', 'master-addons'),
				'type' => Controls_Manager::SLIDER,
				'separator' => 'before',
				'size_units' => ['px'],
				'range' => [
					'px' => [
						'min' => 100,
						'max' => 1000,
						'step' => 5,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				'default' => [
					'unit' => 'px',
					'size' => 100,
				],
				'condition' => [
					'ma_el_team_carousel_preset' => ['-circle', '-circle-animation']
				],
				'selectors' => [
					//						'{{WRAPPER}} .jltma-team-member-circle .jltma-team-member-thumb' =>
					//                            'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};',

					'{{WRAPPER}} .jltma-team-member-circle .jltma-team-member-thumb img,
						{{WRAPPER}} .jltma-team-member-circle-animation .jltma-team-member-thumb .animation_svg_03_center,
						{{WRAPPER}} .jltma-team-member-circle-animation .jltma-team-member-thumb img' => 'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};',

					//						'{{WRAPPER}} .jltma-team-member-circle .jltma-team-member-thumb svg' => 'width: {{SIZE}}{{UNIT}};height: {{SIZE}}{{UNIT}};',

				]
			]
		);

		$this->add_responsive_control(
			'ma_el_team_image_position_left',
			[
				'label' => __('Member Image Position(Left)', 'master-addons'),
				'type' => Controls_Manager::SLIDER,
				'size_units' => ['px', '%', 'em'],
				'default' => [
					'unit' => '%',
					'size' => 45,
				],
				'range' => [
					'px' => [
						'min' => -100,
						'max' => 150,
						'step' => 1,
					]
				],
				'condition' => [
					'ma_el_team_carousel_preset' => ['-circle', '-circle-animation']
				],
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-circle .jltma-team-member-thumb img,
						{{WRAPPER}} .jltma-team-member-circle-animation .jltma-team-member-thumb img' => 'left: {{SIZE}}{{UNIT}};'
				]
			]
		);

		$this->add_responsive_control(
			'ma_el_team_image_position_top',
			[
				'label' => __('Member Image Position(Top)', 'master-addons'),
				'type' => Controls_Manager::SLIDER,
				'size_units' => ['px', '%', 'em'],
				'default' => [
					'unit' => '%',
					'size' => 45,
				],
				'range' => [
					'px' => [
						'min' => -100,
						'max' => 150,
						'step' => 1,
					]
				],
				'condition' => [
					'ma_el_team_carousel_preset' => ['-circle', '-circle-animation']
				],
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-circle .jltma-team-member-thumb img,
						{{WRAPPER}} .jltma-team-member-circle-animation .jltma-team-member-thumb img' => 'top: {{SIZE}}{{UNIT}};'
				]
			]
		);

		$this->add_control(
			'ma_el_team_carousel_avatar_bg',
			[
				'label' => esc_html__('Avatar Background Color', 'master-addons'),
				'type' => Controls_Manager::COLOR,
				'default' => '#826EFF',
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-circle .jltma-team-member-thumb svg.team-avatar-bg' => 'fill: {{VALUE}};',
				],
				'condition' => [
					'ma_el_team_carousel_preset' => '-circle',
				],
			]
		);

		$this->add_control(
			'ma_el_team_carousel_bg',
			[
				'label' => esc_html__('Background Color', 'master-addons'),
				'type' => Controls_Manager::COLOR,
				'default' => '#f9f9f9',
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-basic,
						{{WRAPPER}} .jltma-team-member-circle,
						{{WRAPPER}} .jltma-team-member-social-left,
						{{WRAPPER}} .jltma-team-carousel-wrapper,
						{{WRAPPER}} .swiper-fade .swiper-slide,
						{{WRAPPER}} .jltma-team-member-rounded' => 'background: {{VALUE}};',
					'{{WRAPPER}} .gridder .gridder-show' => 'background-color: {{VALUE}};',
					'{{WRAPPER}} #animation_svg_04 circle' => 'fill: {{VALUE}}'
				],
			]
		);

		$this->add_control(
			'ma_el_team_carousel_content_align',
			[
				'label' => __('Content Alignment', 'master-addons'),
				'type' => Controls_Manager::CHOOSE,
				'options' => Helper::jltma_content_alignment(),
				'default' => 'left',
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-content' => 'text-align: {{VALUE}};',
				],
			]
		);

		$this->end_controls_section();

		//Navigation Style
		$this->start_controls_section(
			'section_style_navigation',
			[
				'label' => __('Navigation', 'master-addons'),
				'tab' => Controls_Manager::TAB_STYLE,
				'conditions' => [
					'relation' => 'or',
					'terms' => [
						[
							'name' => 'navigation',
							'operator' => '!=',
							'value' => 'none',
						],
						[
							'name' => 'ma_el_team_carousel_preset',
							'operator' => '!=',
							'value' => '-content-drawer',
						],
						[
							'name' => 'show_scrollbar',
							'value' => 'yes',
						],
					],
				],
			]
		);

		// Global Navigation Style Controls
		$this->jltma_swiper_navigation_style_controls('team-carousel');

		$this->add_group_control(
			JLTMA_Transition::get_type(),
			[
				'name' => 'arrows',
				'selector' => '{{WRAPPER}} .jltma-swiper__button',
				'condition' => [
					'carousel_arrows' => 'yes'
				]
			]
		);

		$this->end_controls_section();

		/*
		Style Tab: Name
		*/
		$this->start_controls_section(
			'section_team_carousel_name',
			[
				'label' => __('Name', 'master-addons'),
				'tab' => Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_control(
			'ma_el_title_color',
			[
				'label' => __('Color', 'master-addons'),
				'type' => Controls_Manager::COLOR,
				'default' => '#000',
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-name' => 'color: {{VALUE}};',
				],
			]
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name' => 'title_typography',
				'selector' => '{{WRAPPER}} .jltma-team-member-name',
			]
		);
		$this->add_control(
			'ma_el_title_margins',
			[
				'label' => esc_html__('Margin', 'master-addons'),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => ['px', 'em', '%'],
				'placeholder' => [
					'top' => '',
					'right' => '',
					'bottom' => '',
					'left' => '',
				],
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-name ' => 'display:block;margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				]
			]
		);
		$this->end_controls_section();

		$this->start_controls_section(
			'section_team_member_designation',
			[
				'label' => __('Designation', 'master-addons'),
				'tab' => Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_control(
			'ma_el_designation_color',
			[
				'label' => __('Color', 'master-addons'),
				'type' => Controls_Manager::COLOR,
				'default' => '#8a8d91',
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-designation' => 'color: {{VALUE}};',
				],
			]
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name' => 'designation_typography',
				'selector' => '{{WRAPPER}} .jltma-team-member-designation',
			]
		);
		$this->add_control(
			'ma_el_designation_margins',
			[
				'label' => esc_html__('Margin', 'master-addons'),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => ['px', 'em', '%'],
				'placeholder' => [
					'top' => '',
					'right' => '',
					'bottom' => '',
					'left' => '',
				],
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-designation ' => 'display:block;margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				]
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'section_team_carousel_description',
			[
				'label' => __('Description', 'master-addons'),
				'tab' => Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_control(
			'ma_el_description_color',
			[
				'label' => __('Color', 'master-addons'),
				'type' => Controls_Manager::COLOR,
				'default' => '#8a8d91',
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-about,
						{{WRAPPER}} .gridder-expanded-content p.jltma-team-member-desc' => 'color: {{VALUE}};',
				],
			]
		);

		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name' => 'ma_el_description_typography',
				'selector' => '{{WRAPPER}} .jltma-team-member-about',
			]
		);
		$this->add_control(
			'ma_el_description_margins',
			[
				'label' => esc_html__('Margin', 'master-addons'),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => ['px', 'em', '%'],
				'placeholder' => [
					'top' => '',
					'right' => '',
					'bottom' => '',
					'left' => '',
				],
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-about ' => 'display:block;margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				]
			]
		);
		$this->end_controls_section();

		// Global Navigation Controls
		$this->start_controls_section(
			'section_content_navigation',
			[
				'label' => __('Navigation', 'master-addons'),
			]
		);
		$this->jltma_swiper_navigation_controls();
		$this->end_controls_section();

		//  Global Swiper Control Settings
		$this->start_controls_section(
			'section_carousel_settings',
			[
				'label' => __('Carousel Settings', 'master-addons'),
			]
		);

		$slides_per_column = range(1, 6);
		$slides_per_column = array_combine($slides_per_column, $slides_per_column);

		$this->add_responsive_control(
			'columns',
			[
				'type' => Controls_Manager::SELECT,
				'label' => __('Slides per Column', 'master-addons'),
				'description' => __('For Vertical direction this defines the number of slides per row.', 'master-addons'),
				'options' => ['' => __('Default', 'master-addons')] + $slides_per_column,
				'default' => 4,
			]
		);

		$this->jltma_swiper_settings_controls();

		$this->end_controls_section();

		// Global Swiper Item Style
		$this->jltma_swiper_item_style_controls('team-carousel');

		// Help Docs section (links from config.php)
		$this->jltma_help_docs();

		$this->upgrade_to_pro_message();

		$this->start_controls_section(
			'ma_el_team_carousel_social_section',
			[
				'label' => __('Social', 'master-addons'),
				'tab' => Controls_Manager::TAB_STYLE,
				'condition' => [
					'ma_el_team_carousel_preset' => ['-social-left', '-default'],
				],
			]
		);

		$this->start_controls_tabs('ma_el_team_carousel_social_icons_style_tabs');

		$this->start_controls_tab(
			'ma_el_team_carousel_social_icon_control',
			['label' => esc_html__('Normal', 'master-addons')]
		);

		$this->add_control(
			'ma_el_team_carousel_social_icon_color',
			[
				'label' => esc_html__('Icon Color', 'master-addons'),
				'type' => Controls_Manager::COLOR,
				'default' => '#FFF',
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-social li a' => 'color: {{VALUE}};'
				],
			]
		);

		$this->add_control(
			'ma_el_team_carousel_social_color_1',
			[
				'label' => esc_html__('Background Color', 'master-addons'),
				'type' => Controls_Manager::COLOR,
				'default' => '#2231DD',
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-social li a' => 'background: {{VALUE}};'
				],
			]
		);

		$this->end_controls_tab();

		$this->start_controls_tab(
			'ma_el_team_carousel_social_icon_hover_control',
			['label' => esc_html__('Hover', 'master-addons')]
		);

		$this->add_control(
			'ma_el_team_carousel_social_icon_hover_color',
			[
				'label' => esc_html__('Icon Color', 'master-addons'),
				'type' => Controls_Manager::COLOR,
				'default' => '#FFF',
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-social li a:hover' => 'color: {{VALUE}} !important;'
				],
			]
		);

		$this->add_control(
			'ma_el_team_carousel_social_hover_bg_color_1',
			[
				'label' => esc_html__('Background Color', 'master-addons'),
				'type' => Controls_Manager::COLOR,
				'default' => '#DA0971',
				'selectors' => [
					'{{WRAPPER}} .jltma-team-member-social li a:hover' => 'background: {{VALUE}};',
				],
			]
		);

		$this->end_controls_tab();

		$this->end_controls_tabs();

		$this->end_controls_section();
	}

	protected function render()
	{
		$settings = $this->get_settings_for_display();

		// Whitelist allowed HTML tags to prevent XSS
		$allowed_tags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'span', 'p'];
		$title_html_tag = in_array($settings['title_html_tag'], $allowed_tags, true)
			? $settings['title_html_tag']
			: 'h3';

		$team_carousel_classes = $this->get_settings_for_display('ma_el_team_carousel_image_rounded');

		$team_preset = $settings['ma_el_team_carousel_preset'];

		$unique_id = implode('-', [$this->get_id(), get_the_ID()]);

		$this->add_render_attribute([
			'ma_el_team_carousel' => [
				'class' => [
					'jltma-team-carousel-wrapper',
					'jltma-team-carousel' . esc_attr($team_preset),
					'jltma-carousel',
					'jltma-swiper',
					'jltma-swiper__container',
					'swiper',
					'elementor-jltma-element-' . esc_attr($unique_id)
				],
				'data-jltma-template-widget-id' => esc_attr($unique_id)
			],
			'swiper-wrapper' => [
				'class' => [
					'jltma-team-carousel',
					'jltma-swiper__wrapper',
					'swiper-wrapper',
				],
			],

			'swiper-item' => [
				'class' => [
					'jltma-slider__item',
					'jltma-swiper__slide',
					'swiper-slide',
					'jltma-team-carousel' . esc_attr($team_preset) . '-inner'
				],
			],
		]);

		$this->add_render_attribute(
			'ma_el_team_slider_section',
			[
				'class' => 'jltma-team-carousel-wrapper',
				'data-team-preset' => $team_preset,
			]
		);

		$image_size = $settings['thumbnail_size'];
		if (($image_size == 'custom') || is_array($image_size)) {
			$image_size = array_values($settings['thumbnail_custom_dimension']);
		}

		?>

		<?php if ($team_preset == '-content-drawer') { ?>

			<div <?php echo $this->get_render_attribute_string('ma_el_team_slider_section'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor get_render_attribute_string() returns safe HTML attributes ?>>
				<!-- Gridder navigation -->
				<ul class="gridder">

					<?php
					$demo_images = [];

					if (
						empty($settings['team_carousel_repeater'][0]['ma_el_team_carousel_image'])
						&& empty($settings['team_carousel_repeater'][1]['ma_el_team_carousel_image'])
						&& empty($settings['team_carousel_repeater'][0]['ma_el_team_carousel_image'])
					) {
						$demo_images[] = Helper::jltma_placeholder_images();
					}

					foreach ($settings['team_carousel_repeater'] as $key => $member) {

						$team_carousel_image = $member['ma_el_team_carousel_image'];
						$image_id = $member['ma_el_team_carousel_image']['id'];
						if (empty($team_carousel_image)) {
							$team_carousel_image = $demo_images;
						}

						$team_member_image_src = '';
						if (!empty($team_carousel_image)) {
							if (isset($image_id) && $image_id) {
								$team_member_image_src = wp_get_attachment_image(
									$image_id,
									$image_size,
									false,
									[
										'class' => 'team-slider-image',
										'alt' => esc_attr($member['ma_el_team_carousel_name']),
									]
								);
							} else {
								$team_member_image_src = "<img src=" . esc_url($team_carousel_image['url']) . ">";
							}
						}

						?>

						<li class="gridder-list" data-griddercontent="#jltma-team<?php echo esc_attr($key) + 1; ?>">
							<?php
							// Thumbnail Image
							echo Helper::wp_kses_custom($team_member_image_src); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper::wp_kses_custom() is the plugin's safe HTML sanitizer
							?>
							<div class="jltma-team-drawer-hover-content">

								<<?php echo esc_html($title_html_tag); ?>>
									<?php echo esc_html($member['ma_el_team_carousel_name']); ?>
								</<?php echo esc_html($title_html_tag); ?>>

								<span class="jltma-team-member-designation">
									<?php echo esc_html($member['ma_el_team_carousel_designation']); ?>
								</span>
							</div>
						</li>

					<?php } ?>
				</ul>

				<!-- Gridder content -->
				<?php foreach ($settings['team_carousel_repeater'] as $key => $member) { ?>

					<div id="jltma-team<?php echo esc_attr($key) + 1; ?>" class="gridder-content">
						<div class="jltma-content-left">
							<span class="jltma-team-member-designation">
								<?php echo esc_html($member['ma_el_team_carousel_designation']); ?>
							</span>
							<<?php echo esc_html($title_html_tag); ?> class="jltma-team-member-name">
								<?php echo wp_kses_post( $this->parse_text_editor($member['ma_el_team_carousel_name']) ); ?>
							</<?php echo esc_html($title_html_tag); ?>>
							<p class="jltma-team-member-desc">
								<?php echo wp_kses_post( $this->parse_text_editor($member['ma_el_team_carousel_description']) ); ?>
							</p>
						</div>

						<div class="jltma-content-right">
							<?php if ($member['ma_el_team_carousel_enable_social_profiles'] == 'yes'): ?>
								<ul class="list-inline jltma-team-member-social">

									<?php if (!empty($member['ma_el_team_carousel_facebook_link']['url'])): ?>
										<?php $target = $member['ma_el_team_carousel_facebook_link']['is_external'] ? ' target="_blank"' : ''; ?>
										<li>
											<a href="<?php echo esc_url($member['ma_el_team_carousel_facebook_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fa fa-facebook"></i></a>
										</li>
									<?php endif; ?>

									<?php if (!empty($member['ma_el_team_carousel_twitter_link']['url'])): ?>
										<?php $target = $member['ma_el_team_carousel_twitter_link']['is_external'] ? ' target="_blank"' : ''; ?>
										<li>
											<a href="<?php echo esc_url($member['ma_el_team_carousel_twitter_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fa fa-twitter"></i></a>
										</li>
									<?php endif; ?>

									<?php if (!empty($member['ma_el_team_carousel_instagram_link']['url'])): ?>
										<?php $target = $member['ma_el_team_carousel_instagram_link']['is_external'] ?
											' target="_blank"' : ''; ?>
										<li>
											<a href="<?php echo esc_url($member['ma_el_team_carousel_instagram_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fa fa-instagram"></i></a>
										</li>
									<?php endif; ?>

									<?php if (!empty($member['ma_el_team_carousel_linkedin_link']['url'])): ?>
										<?php $target = $member['ma_el_team_carousel_linkedin_link']['is_external'] ? ' target="_blank"' : ''; ?>
										<li>
											<a href="<?php echo esc_url($member['ma_el_team_carousel_linkedin_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fa fa-linkedin"></i></a>
										</li>
									<?php endif; ?>

									<?php if (!empty($member['ma_el_team_carousel_dribbble_link']['url'])): ?>
										<?php $target = $member['ma_el_team_carousel_dribbble_link']['is_external'] ? ' target="_blank"' : ''; ?>
										<li>
											<a href="<?php echo esc_url($member['ma_el_team_carousel_dribbble_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fa fa-dribbble"></i></a>
										</li>
									<?php endif; ?>

									<?php if (!empty($member['ma_el_team_carousel_tiktok_link']['url'])): ?>
										<?php $target = $member['ma_el_team_carousel_tiktok_link']['is_external'] ? ' target="_blank"' : ''; ?>
										<li>
											<a href="<?php echo esc_url($member['ma_el_team_carousel_tiktok_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fab fa-tiktok"></i></a>
										</li>
									<?php endif; ?>

									<?php if (!empty($member['ma_el_team_carousel_youtube_link']['url'])): ?>
										<?php $target = $member['ma_el_team_carousel_youtube_link']['is_external'] ? ' target="_blank"' : ''; ?>
										<li>
											<a href="<?php echo esc_url($member['ma_el_team_carousel_youtube_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fa fa-youtube"></i></a>
										</li>
									<?php endif; ?>

									<?php if (!empty($member['ma_el_team_carousel_email_link'])): ?>
										<li>
											<a href="mailto:<?php echo esc_attr($member['ma_el_team_carousel_email_link']); ?>"><i
													class="fa fa-envelope"></i></a>
										</li>
									<?php endif; ?>

								</ul>
							<?php endif; ?>
						</div>
					</div>
				<?php } ?>

			</div>

		<?php } else {

			//Global Header Function
			$this->jltma_render_swiper_header_attribute('team-carousel');
			$this->add_render_attribute('carousel', 'class', ['jltma-team-carousel-slider']);
			?>

			<div <?php echo $this->get_render_attribute_string('carousel'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor get_render_attribute_string() returns safe HTML attributes ?>>
				<div <?php echo $this->get_render_attribute_string('ma_el_team_carousel'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor get_render_attribute_string() returns safe HTML attributes ?>>
					<div <?php echo $this->get_render_attribute_string('swiper-wrapper'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor get_render_attribute_string() returns safe HTML attributes ?>>
						<?php
						$demo_images = [];

						if (
							empty($settings['team_carousel_repeater'][0]['ma_el_team_carousel_image'])
							&& empty($settings['team_carousel_repeater'][1]['ma_el_team_carousel_image'])
							&& empty($settings['team_carousel_repeater'][0]['ma_el_team_carousel_image'])
						) {
							$demo_images[] = Helper::jltma_placeholder_images();
						}

						foreach ($settings['team_carousel_repeater'] as $key => $member) {
							$team_carousel_image = $member['ma_el_team_carousel_image'];
							$image_id = $team_carousel_image['id'];
							if (empty($team_carousel_image)) {
								$team_carousel_image = $demo_images;
							}

							$team_member_image_src = '';
							if (!empty($team_carousel_image)) {
								if (isset($image_id) && $image_id) {
									$team_member_image_src = wp_get_attachment_image(
										$image_id,
										$image_size,
										false,
										[
											'class' => 'team-slider-image',
											'alt' => esc_attr($member['ma_el_team_carousel_name']),
										]
									);
								} else {
									$team_member_image_src = "<img src=" . esc_url($team_carousel_image['url']) . ">";
								}
							}

							?>

							<div <?php echo $this->get_render_attribute_string('swiper-item'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor get_render_attribute_string() returns safe HTML attributes ?>>
								<div class="jltma-team-member<?php echo esc_attr($team_preset); ?> text-center">
									<div class="jltma-team-member-thumb">
										<?php
										// if( $team_preset == '-circle' && isset( $settings['ma_el_team_circle_image'] ) && !isset( $settings['ma_el_team_circle_image_animation'] )) {
										if ($team_preset == '-circle' && isset($settings['ma_el_team_circle_image'])) {

											// SVG Image Circle
											$file_path = JLTMA_PATH . 'assets/images/circlesvg/' . esc_attr($settings['ma_el_team_circle_image']) . '.svg';
											echo file_get_contents($file_path); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- local SVG file from plugin assets directory

											// Thumbnail Image
											echo Helper::wp_kses_custom($team_member_image_src); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper::wp_kses_custom() is the plugin's safe HTML sanitizer

										} elseif ($team_preset == '-circle-animation' && isset($settings['ma_el_team_circle_image_animation'])) {

											if ($settings['ma_el_team_circle_image_animation'] == "animation_svg_02") {

												echo '<div class="animation_svg_02">' . Helper::wp_kses_custom($team_member_image_src) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper::wp_kses_custom() is the plugin's safe HTML sanitizer
											} elseif ($settings['ma_el_team_circle_image_animation'] == "animation_svg_03") {

												echo '<div class="animation_svg_03"></div><div class="animation_svg_03"></div><div class="animation_svg_03"></div><div class="animation_svg_03_center">' . Helper::wp_kses_custom($team_member_image_src) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper::wp_kses_custom() is the plugin's safe HTML sanitizer
											} else {

												$file_path = JLTMA_PATH . 'assets/images/animation/' .
													$settings['ma_el_team_circle_image_animation'] . '.svg';
												echo file_get_contents($file_path); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- local SVG file from plugin assets directory
												echo Helper::wp_kses_custom($team_member_image_src); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper::wp_kses_custom() is the plugin's safe HTML sanitizer
											}
										} else {
											echo Helper::wp_kses_custom($team_member_image_src); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper::wp_kses_custom() is the plugin's safe HTML sanitizer
										} ?>

									</div>
									<div class="jltma-team-member-content">
										<<?php echo esc_html($title_html_tag); ?> class="jltma-team-member-name">
											<?php echo wp_kses_post( $this->parse_text_editor($member['ma_el_team_carousel_name']) );
											?>
										</<?php echo esc_html($title_html_tag); ?>>
										<span class="jltma-team-member-designation">
											<?php echo wp_kses_post( $this->parse_text_editor($member['ma_el_team_carousel_designation']) ); ?>
										</span>
										<p class="jltma-team-member-about">
											<?php echo wp_kses_post( $this->parse_text_editor($member['ma_el_team_carousel_description']) ); ?>
										</p>
										<?php if ($member['ma_el_team_carousel_enable_social_profiles'] == 'yes'): ?>
											<ul class="list-inline jltma-team-member-social">

												<?php if (!empty($member['ma_el_team_carousel_facebook_link']['url'])): ?>
													<?php $target = $member['ma_el_team_carousel_facebook_link']['is_external'] ? ' target="_blank"' : ''; ?>
													<li>
														<a href="<?php echo esc_url($member['ma_el_team_carousel_facebook_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fa fa-facebook"></i></a>
													</li>
												<?php endif; ?>

												<?php if (!empty($member['ma_el_team_carousel_twitter_link']['url'])): ?>
													<?php $target = $member['ma_el_team_carousel_twitter_link']['is_external'] ? ' target="_blank"' : ''; ?>
													<li>
														<a href="<?php echo esc_url($member['ma_el_team_carousel_twitter_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fa fa-twitter"></i></a>
													</li>
												<?php endif; ?>

												<?php if (!empty($member['ma_el_team_carousel_instagram_link']['url'])): ?>
													<?php $target = $member['ma_el_team_carousel_instagram_link']['is_external'] ?
														' target="_blank"' : ''; ?>
													<li>
														<a href="<?php echo esc_url(
															$member['ma_el_team_carousel_instagram_link']['url']
														); ?>" <?php echo esc_attr($target); ?>><i class="fa fa-instagram"></i></a>
													</li>
												<?php endif; ?>

												<?php if (!empty($member['ma_el_team_carousel_linkedin_link']['url'])): ?>
													<?php $target = $member['ma_el_team_carousel_linkedin_link']['is_external'] ? ' target="_blank"' : ''; ?>
													<li>
														<a href="<?php echo esc_url($member['ma_el_team_carousel_linkedin_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fa fa-linkedin"></i></a>
													</li>
												<?php endif; ?>

												<?php if (!empty($member['ma_el_team_carousel_dribbble_link']['url'])): ?>
													<?php $target = $member['ma_el_team_carousel_dribbble_link']['is_external'] ? ' target="_blank"' : ''; ?>
													<li>
														<a href="<?php echo esc_url($member['ma_el_team_carousel_dribbble_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fa fa-dribbble"></i></a>
													</li>
												<?php endif; ?>

												<?php if (!empty($member['ma_el_team_carousel_tiktok_link']['url'])): ?>
													<?php $target = $member['ma_el_team_carousel_tiktok_link']['is_external'] ? ' target="_blank"' : ''; ?>
													<li>
														<a href="<?php echo esc_url($member['ma_el_team_carousel_tiktok_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fab fa-tiktok"></i></a>
													</li>
												<?php endif; ?>

												<?php if (!empty($member['ma_el_team_carousel_youtube_link']['url'])): ?>
													<?php $target = $member['ma_el_team_carousel_youtube_link']['is_external'] ? ' target="_blank"' : ''; ?>
													<li>
														<a href="<?php echo esc_url($member['ma_el_team_carousel_youtube_link']['url']); ?>" <?php echo esc_attr($target); ?>><i class="fa fa-youtube"></i></a>
													</li>
												<?php endif; ?>

												<?php if (!empty($member['ma_el_team_carousel_email_link'])): ?>
													<li>
														<a href="mailto:<?php echo esc_attr($member['ma_el_team_carousel_email_link']); ?>"><i
																class="fa fa-envelope"></i></a>
													</li>
												<?php endif; ?>

											</ul>
										<?php endif; ?>
									</div>
								</div>
							</div>
						<?php } // repeater loop end
						?>
					</div> <!-- swiper-wrapper -->

				</div>

				<?php $this->render_swiper_navigation(); ?>

				<?php if ('yes' === $settings['show_scrollbar']) { ?>
					<div class="swiper-scrollbar"></div>
				<?php } ?>

			<?php } // carousel layout
		?>
		</div>

		<?php
	}
}
