<?php
/*
Element: Text Slider
*/
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Utils;
use Elementor\Group_Control_Typography;
class PLS_Elementor_TextSlider extends PLS_Elementor_Widget_Base {
	/**
	 * Retrieve the widget name.
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
        return 'pls-text-slider';
    }

	/**
     * Get widget title.
     *
     * Retrieve widget title.
     *
     * @since 1.0.0
     * @access public
     *
     * @return string Widget title.
     */
    public function get_title() {
        return esc_html__( 'Text Slider', 'modave-core' );
    }

    /**
     * Get widget icon.
     *
     * Retrieve Team widget icon.
     *
     * @since 1.0.0
     * @access public
     *
     * @return string Widget icon.
     */
    public function get_icon() {
        return 'pls-icon eicon-carousel';
    }
	
	/**
     * Register widget controls.
     *
     * Adds different input fields to allow the user to change and customize the widget settings.
     *
     * @since 1.0.0
     * @access protected
     */
    protected function register_controls() {
		
		$this->start_controls_section(
			'section_content_tab',
			array(
				'label'     => esc_html__( 'General', 'modave-core' ),
				'tab'       => Controls_Manager::TAB_CONTENT,
			)
		);
		
		
		$repeater = new Repeater();		
		$repeater->add_control(
			'slider_text',
			[
				'label' 		=> esc_html__( 'Title', 'modave-core' ),
				'type' 			=> Controls_Manager::TEXTAREA,
				'default' 		=> '',
				'placeholder'	=> esc_html__( 'Enter title', 'modave-core' ),
				'dynamic' 		=> [
					'active' 	=> true,
				],
			]
		);
		$this->add_control(
            'slider_texts',
            [
                'label' 	=> esc_html__( 'Slider Texts', 'modave-core' ),
                'type' 		=> Controls_Manager::REPEATER,
				'fields' 	=> $repeater->get_controls(),
				'default' 	=> [
					[
						'slider_text' 		=> '10% off on all summer essentials!',
					],
					[
						'slider_text' 		=> 'Get summer-ready: 10% off swim suits',
					],
					[
						'slider_text' 		=> '10% off on all product on shop',
					],
					[
						'slider_text' 		=> 'Get 10% off on selected items',
					],
				],
				'title_field' => '{{{ slider_text }}}',
            ]
        );
		
		$this->end_controls_section();
		
		$this->start_controls_section(
			'section_content_slider',
			array(
				'label'     => esc_html__( 'Slider Settings', 'modave-core' ),
				'tab'       => Controls_Manager::TAB_CONTENT,
			)
		);
		$this->add_control(
			'slider_autoplay',
			[
				'label'     => esc_html__( 'Autoplay', 'modave-core' ),
				'type'      => Controls_Manager::SWITCHER,
				'default'   => 'yes',
			]
		);
		$this->add_control(
			'slider_autoplay_delay',
			[
				'label' 		=> esc_html__( 'Autoplay Delay', 'modave-core' ),
				'type' 			=> Controls_Manager::NUMBER,
				'default' 		=> 2000,
				'condition' 	=> [
					'slider_autoplay' => 'yes',
				],
			]
		);
		$this->add_control(
			'slider_autoplay_speed',
			[
				'label' 		=> esc_html__( 'Transition Speed', 'modave-core' ),
				'type' 			=> Controls_Manager::NUMBER,
				'default' 		=> 1000,
			]
		);
		$this->add_control(
			'slider_pause_on_hover',
			[
				'label'     => esc_html__( 'Pause On Hover', 'modave-core' ),
				'type'      => Controls_Manager::SWITCHER,
				'default'   => 'yes',
				'condition' => [
					'slider_autoplay' => [ 'yes' ],
				],
			]
		);
		$this->add_control(
			'slider_loop',
			[
				'label'     => esc_html__( 'Loop', 'modave-core' ),
				'type'      => Controls_Manager::SWITCHER,
				'default'   => 'yes',
			]
		);
		$this->end_controls_section();
		
		$this->start_controls_section(
			'style_section',
			[
				'label' => esc_html__( 'Text', 'modave-core' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);
		
		$this->add_control(
			'text_color',
			[
				'label'     => esc_html__( 'Text Color', 'modave-core' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .pls-slider-text, {{WRAPPER}}.elementor-widget-pls-text-slider .pls-slider-next, {{WRAPPER}}.elementor-widget-pls-text-slider .pls-slider-prev' => 'color: {{VALUE}}',
				],
			]
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name'     => 'text_typography',
				'label'    => esc_html__( 'Typography', 'modave-core' ),
				'selector' => '{{WRAPPER}} .pls-slider-text',
			]
		);
		$this->add_responsive_control(
			'content_width',
			[
				'label'			=> esc_html__( 'Slider Width', 'modave-core' ),
				'type'			=> Controls_Manager::SLIDER,
				'size_units' 	=> [ '%', 'px' ],
				'range'			=> [
					'px' 	=> [ 'min' => 200, 'max' => 1920, 'step' => 1 ], 
					'%' 	=> [ 'min' => 20, 'max' => 100, 'step' => 1 ],
				],
				'selectors'		=> [
					'{{WRAPPER}}.elementor-widget-pls-text-slider .pls-slider-wrapper' => 'max-width: {{SIZE}}{{UNIT}};margin: 0 auto;',
				],
			]
		);
		$this->end_controls_section();		
	}
	
	protected function render() {
		
		$settings = $this->get_settings();
		$settings = wp_parse_args( $settings, [
			'slider_navigation' 	=> 'yes',
			'slider_dots' 			=> 0,
			'slides_to_show' 		=> 1,
			'slides_to_show_tablet' => 1,
			'slides_to_show_mobile' => 1,
		]);
		extract( $settings );
		$settings['id'] 	= pls_uniqid( 'pls-text-slider-' );
		$class				= array( 'pls-element', 'pls-text-slider', 'swiper', 'pls-slider' );
		$settings['class']	= implode( ' ', $class );
		$settings['style'] 	= 'style-1';
		$settings['slider_class'] 	= 'swiper-wrapper';
		$settings['slider_class'] 	.= ' slider-col-lg-' .$slides_to_show;
		$settings['slider_class'] 	.= ' slider-col-md-' .$slides_to_show_tablet;
		$settings['slider_class'] 	.= ' slider-col-' .$slides_to_show_mobile;
		$settings['slider_options'] 	= pls_slider_attributes( $settings);
		pls_core_get_templates( 'elements-widgets/text-slider', $settings );
	}
}

$widgets_manager->register( new PLS_Elementor_TextSlider() );