<?php

namespace XIMSAPLUGIN\Element;

use Elementor\Controls_Manager;
use Elementor\Controls_Stack;
use Elementor\Group_Control_Typography;
use Elementor\Scheme_Typography;
use Elementor\Scheme_Color;
use Elementor\Group_Control_Border;
use Elementor\Repeater;
use Elementor\Widget_Base;
use Elementor\Utils;
use Elementor\Group_Control_Text_Shadow;
use Elementor\Group_Control_Background;
use Elementor\Plugin;

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

class digm_slider extends Widget_Base {

	/**
	 * Get widget name.
	 *
	 * Retrieve Elementor widget name.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'dgm-slider-content';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Digital Marketing SLider', 'ximsa' );
	}

	/**
	 * Get widget icon.
	 *
	 * Retrieve Elementor widget icon.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'gl-custom-icon';
	}

	/**
	 * Get widget categories.
	 *
	 * Retrieve the list of categories the Elementor widget belongs to.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories() {
		return [ 'ximsa' ];
	}

	/**
	 * Register Elementor 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(
            'feature_content_options',
            [
                'label' => __( 'feature Content Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        
        $repeater = new \Elementor\Repeater();
        
        $repeater->add_control(
			'thumb_img',
			[
				'label' => esc_html__( 'Thumb Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'thumb_lg_img',
			[
				'label' => esc_html__( 'Thumb Learge Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        
        $repeater->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'shortinfo',
			[
				'label' => esc_html__( 'Short Description', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'video_link',
			[
				'label' => esc_html__( 'Video Link', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'btn_label',
			[
				'label' => esc_html__( 'Button Label', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'btn_link',
			[
				'label' => esc_html__( 'Button LInk', 'ximsa' ),
				'type' => Controls_Manager::URL,
                'label_block' => true,
			]
		);
        
        $this->add_control(
			'slidersitem',
			[
				'label' => esc_html__( 'Sliders Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ title }}}',
			]
		);
		$this->end_controls_section();

        $this->start_controls_section(
            'slide_settings_style',
            [
                'label' => __( 'Slider Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
			'container_width',
			[
				'label' => esc_html__( 'Container Width', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 2000,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				
				'selectors' => [
					'{{WRAPPER}} .container, .container-lg, .container-md, .container-sm, .container-xl, .container-xxl' => 'max-width: {{SIZE}}{{UNIT}};',
				],
			]
		);
        
        $this->add_control(
            'slider_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Slider Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'slider_lter_cl',
            [
                'label'     => esc_html__( 'Slider Letter BG Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dm-slider-text h1:before' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'slider_title_cl',
            [
                'label'     => esc_html__( 'Slider Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dm-slider-item.slick-current .xis-dm-slider-text h1' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'se_th_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-dm-slider-item.slick-current .xis-dm-slider-text h1',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'se_desc_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Desc Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'se_decs_color',
            [
                'label'     => esc_html__( 'Desc Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dm-slider-item.slick-current .xis-dm-slider-text p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'se_desc_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-dm-slider-item.slick-current .xis-dm-slider-text p',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'video_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Video Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'video_clr',
            [
                'label'     => esc_html__( 'Video Icon Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dm-slider-btn .xis-dm-slide-video-btn a' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'video_bg_cl',
            [
                'label'     => esc_html__( 'Background Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dm-slider-btn .xis-dm-slide-video-btn a' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        

		$this->end_controls_section();
        $this->start_controls_section(
            'button__content',
            [
                'label' => __( 'Slider Button Style', 'ximsa' ),
                'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name'           => 'btn_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-dm-slider-btn .xis-dm-btn a
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
			'btnwidth',
			[
				'label' => esc_html__( 'Width', 'ximsa' ),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
						'step' => 5,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				'selectors' => [
					'{{WRAPPER}} .xis-dm-slider-btn .xis-dm-btn a' => 'width: {{SIZE}}{{UNIT}};',
				],
			]
		);
        $this->add_control(
			'btnheight',
			[
				'label' => esc_html__( 'Height', 'ximsa' ),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
						'step' => 5,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				'selectors' => [
					'{{WRAPPER}} .xis-dm-slider-btn .xis-dm-btn a' => 'height: {{SIZE}}{{UNIT}};',
				],
			]
		);
        $this->start_controls_tabs( '_banner_button_1' );
        $this->start_controls_tab(
            '_glow-extension_btn__banner_normal',
            [
                'label' => esc_html__( 'Normal', 'glow-extension-extension' ),
            ]
        );
        $this->add_control(
            'btn__color',
            [
                'label'     => esc_html__( 'Color', 'glow-extension-extension' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dm-slider-btn .xis-dm-btn a' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name'     => 'btn_bg_color',
                'label'    => __( 'Background', 'glow-extension-extension' ),
                'types'    => ['classic', 'gradient'],
                'exclude'  => ['image'],
                'selector' => '
                    {{WRAPPER}} .xis-dm-slider-btn .xis-dm-btn a
                ',
            ]
        );
        $this->add_responsive_control(
            'btn_border_radious',
            [
                'label'      => esc_html__( 'Border Radius', 'glow-extension-extension' ),
                'type'       => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors'  => [
                    '{{WRAPPER}} .xis-dm-slider-btn .xis-dm-btn a' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        
        $this->end_controls_tab();
        $this->start_controls_tab(
            '_glow-extension_btn_hover',
            [
                'label' => esc_html__( 'Hover', 'glow-extension-extension' ),
            ]
        );
        $this->add_control(
            'btn__hover_color',
            [
                'label'     => esc_html__( 'Color', 'glow-extension-extension' ),
                'type'      => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dm-slider-btn .xis-dm-btn a:hover' => 'color: {{VALUE}}',
                ],
            ]
        );
        $this->add_group_control(
            \Elementor\Group_Control_Background::get_type(),
            [
                'name'     => 'btn_hover_bg_color',
                'label'    => __( 'Background', 'glow-extension-extension' ),
                'types'    => ['classic', 'gradient'],
                'exclude'  => ['image'],
                'selector' => '
                    {{WRAPPER}} .xis-dm-slider-btn .xis-dm-btn a:hover
                ',
            ]
        );
        $this->add_responsive_control(
            'btn_hover_border_radious',
            [
                'label'      => esc_html__( 'Border Radius', 'glow-extension-extension' ),
                'type'       => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors'  => [
                    '{{WRAPPER}} .xis-dm-slider-btn .xis-dm-btn a:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',                    
                ],
            ]
        );
        $this->end_controls_tab();
        $this->end_controls_tabs();
        $this->end_controls_section();
	}
		


	protected function render() {
		
		
		$settings = $this->get_settings_for_display(); ?>
		<!-- Start of Slider section
        ============================================= -->
        <section id="xis-dm-slider" class="xis-dm-slider-section">
            <div class="xis-dm-slider-content position-relative">
                <div class="xis-dm-slider-nav">
                    <?php foreach($settings['slidersitem'] as $item):?>
                    <div class="xis-dm-slider-nav-img">
                        <img src="<?php echo esc_url($item['thumb_img']['url']);?>" alt="<?php echo esc_url($item['thumb_img']['alt']);?>">
                    </div>
                    <?php endforeach;?>
                </div>
                <div class="xis-dm-slider-area-for">
                    <?php foreach($settings['slidersitem'] as $item):?>
                    <div class="xis-dm-slider-item d-flex justify-content-between">
                        <div class="xis-dm-slider-text xis-dm-headline pera-content">
                            <h1><?php echo wp_kses( $item['title'], true );?></h1>
                            <p><?php echo wp_kses($item['shortinfo'], true);?></p>
                            <div class="xis-dm-slider-btn d-flex align-items-center">
                                <div class="xis-dm-slide-video-btn">
                                    <a class="video_box d-flex justify-content-center align-items-center" class="video_box" href="<?php echo esc_url($item['video_link']);?>">
                                        <i class="fas fa-play"></i>
                                    </a>
                                </div>
                                <div class="xis-dm-btn">
                                    <a class="d-flex justify-content-center align-items-center" href="<?php echo esc_url($item['btn_link']['url']);?>"><?php echo esc_html($item['btn_label']);?> <i class="fal fa-chevron-circle-right"></i></a>
                                </div>
                            </div>
                        </div>
                        <div class="xis-dm-slider-img">
                            <img src="<?php echo esc_url($item['thumb_lg_img']['url']);?>" alt="<?php echo esc_url($item['thumb_lg_img']['alt']);?>">
                        </div>
                    </div>
                    <?php endforeach;?>
                </div>
            </div>
        </section>
    <!-- End of Slider section
        ============================================= -->
		<?php 
      }
	
	

}
