<?php
/**
 * Elementor Logo Carousel Widget.
 *
 * Elementor widget that inserts an embbedable content into the page, from any given URL.
 *
 * @since 1.0.5
 */
class Elementor_Logo_Carousel_Widget extends \Elementor\Widget_Base {

	/**
	 * Get widget name.
	 *
	 * Retrieve Logo Carousel widget name.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return string Widget name.
	 */
	public function get_name() {
		return 'ea-logo';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Logo Carousel widget title.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return __( 'Logo Carousel', 'endless-addons' );
	}

	/**
	 * Get widget icon.
	 *
	 * Retrieve Logo Carousel widget icon.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return string Widget icon.
	 */
	public function get_icon() {
		return 'fa fa-sliders';
	}

	/**
	 * Get widget categories.
	 *
	 * Retrieve the list of categories the Logo Carousel widget belongs to.
	 *
	 * @since 1.0.5
	 * @access public
	 *
	 * @return array Widget categories.
	 */
	public function get_categories() {
		return [ 'endless-elements' ];
	}

	/**
	 * Register Logo Carousel widget controls.
	 *
	 * Adds different input fields to allow the user to change and customize the widget settings.
	 *
	 * @since 1.0.5
	 * @access protected
	 */
	protected function register_controls() {

		$this->start_controls_section(
			'default_section',
			[    
				'label' => __( 'Settings', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT
			]
		);

		$this->add_control(
			'show_logo_carousel',
			[
				'label' => __( 'Show/Hide Logo Carousel Section', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::CHOOSE,
				'options' => [
					'show' => [
						'title' => __( 'Show', 'endless-addons' ),
						'icon' => 'fa fa-check'
					],
					'hide' => [
						'title' => __( 'Hide', 'endless-addons' ),
						'icon' => 'fa fa-close'
					]
				],
				'default' => 'show',
				'toggle' => true
			]
		);

		$this->add_control(
			'select_logo_carousel_style',
			[
				'label' => __( 'Select Logo Carousel Style', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'input_type' => 'SELECT',
				'options' => [
					'style-01' => __( 'Style 01', 'endless-addons' ),
					'style-02' => __( 'Style 02', 'endless-addons' ),
					'style-03' => __( 'Style 03', 'endless-addons' ),
					'style-04' => __( 'Style 04', 'endless-addons' ),
					'style-05' => __( 'Style 05', 'endless-addons' ),
					'style-06' => __( 'Style 06', 'endless-addons' ),
					'style-07' => __( 'Style 07', 'endless-addons' ),
					'style-08' => __( 'Style 08', 'endless-addons' ),
					'style-09' => __( 'Style 09', 'endless-addons' ),
					'style-10' => __( 'Style 10', 'endless-addons' )
				],
				'default' => 'style-01'
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'logo_carousel_section',
			[
				'label' => __( 'Logo Carousel Section', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'logo_carousel_title',
			[
				'label' => __( 'Logo Carousel Title', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'input_type' => 'text',
				'placeholder' => __( 'Title', 'endless-addons' ),
				'default'  => __( 'Design 1', 'endless-addons' )
			]
		);

		$this->add_control(
			'logo_carousel_desc',
			[
				'label' => __( 'Logo Carousel Description', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::WYSIWYG,
				'input_type' => 'WYSIWYG',
				'placeholder' => __( 'Description', 'endless-addons' ),
				'default' => __( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt dolore magna aliqua. Quis ipsum suspendisse ultrices gravida.', 'endless-addons')
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'section_background',
				'label' => __( 'Background', 'plugin-domain' ),
				'types' => [ 'classic', 'gradient', 'video' ],
				'selector' => '{{WRAPPER}} .ea-logo-carousel-area',
			]
		);

		$this->add_control(
			'logo_carousel_content',
			[
				'label' => __( 'Logo Carousel Content', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::WYSIWYG,
				'input_type' => 'WYSIWYG',
				'placeholder' => __( 'Description', 'endless-addons' ),
				'default' => __( 'Donec rutrum congue leo eget malesuada. Pellentesque in ipsum id orci porta dapibus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla quis lorem ut libero malesuada feugiat. Pellentesque in ipsum id orci porta dapibus. Proin eget tortor risus.', 'endless-addons'),
				'condition' => [
                    'select_logo_carousel_style' => 'style-09',
                ]
			]
		);

		$this->end_controls_section();

		$this->start_controls_section(
			'logo_carousel_gallery',
			[
				'label' => __( 'Logo Carousel Gallery', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'logo_carousel_logos',
			[
				'label' => __( 'Gallery', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::GALLERY,
				'input_type' => 'gallery',
				'condition' => [
                    'select_logo_carousel_style' => array('style-02', 'style-03', 'style-04', 'style-05', 'style-06', 'style-07', 'style-09', 'style-10')
                ]
			]
		);

        $repeater = new \Elementor\Repeater();

        $repeater->add_control(
			'logo_carousel_image', [
				'label' => __( 'White Image', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::MEDIA,
			]
		);

		$repeater->add_control(
			'logo_carousel_white_image', [
				'label' => __( 'Image', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::MEDIA,
			]
		);

        $this->add_control(
			'single_logo_carousel_image',
			[
				'label' => __( 'Single Logo Carousel', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'default' => [
					[
						'list_title' => __( 'Logo Carousel #1', 'endless-addons' ),
						'list_content' => __( 'Logo Carousel Content', 'endless-addons' ),
					],
				
				],
				'condition' => [
                    'select_logo_carousel_style' => array('style-01', 'style-08'),
                ]
			]
		);

        $this->end_controls_section();

		$this->start_controls_section(
			'logo_carousel_style',
			[
				'label' => __( 'Logo Carousel Style', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE
			]
		);

		$this->add_control(
			'logo_carousel_title_color',
			[
				'label' => __( 'Section Title Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-logo-carousel-area .section-title h2' => 'color: {{VALUE}}'
                ]
			]
		);

		$this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'logo_carousel_title_typography',
                'label' => __( 'Section Title Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-logo-carousel-area .section-title h2'
            ]
        );

        $this->add_control(
			'logo_carousel_desc_color',
			[
				'label' => __( 'Section Description Color', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::COLOR,
				'selectors' => [
                    '{{WRAPPER}} .ea-logo-carousel-area .section-title p' => 'color: {{VALUE}}'
                ]
			]
		);

        $this->add_group_control(
            \Elementor\Group_Control_Typography::get_type(),
            [
                'name' => 'logo_carousel_desc_typography',
                'label' => __( 'Section Description Typography', 'endless-addons' ),
                'scheme' => \Elementor\Core\Schemes\Typography::TYPOGRAPHY_1,
                'selector' => '{{WRAPPER}} .ea-logo-carousel-area .section-title p'
            ]
        );

		$this->end_controls_section();

		$this->start_controls_section(
			'logo_img_style',
			[
				'label' => __( 'Logo Image Style', 'endless-addons' ),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE
			]
		);

        $this->add_control(
			'logo_img_height',
			[
				'label' => __( 'Logo Image Height', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'range' => [
					'px' => [
						'min' => 50,
						'max' => 500
					]
				],
				'selectors' => [
					'{{WRAPPER}} .ea-logo-carousel-area .ea-single-logo-carousel img' => 'height: {{SIZE}}{{UNIT}}',
				]
			]
		);

		$this->add_control(
			'logo_img_width',
			[
				'label' => __( 'Logo Image Width', 'endless-addons' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'range' => [
					'px' => [
						'min' => 50,
						'max' => 500
					]
				],
				'selectors' => [
					'{{WRAPPER}} .ea-logo-carousel-area .ea-single-logo-carousel img' => 'width: {{SIZE}}{{UNIT}}',
				],
			]
		);

		$this->add_control(
            'contact_img_border_radius',
            [
                'label' => __( 'Image Border Radius', 'endless-addons' ),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'separator' => 'after',
                'selectors' => [
                    '{{WRAPPER}} .ea-logo-carousel-area .ea-single-logo-carousel img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

		$this->end_controls_section();

		$this->start_controls_section(
			'_section_overlay_style',
			[
				'label' => __('Background Overlay', 'endless-addons'),
				'tab' => \Elementor\Controls_Manager::TAB_STYLE,
			]
		);

		$this->start_controls_tabs('_tabs_overlay_style');

		$this->start_controls_tab(
			'_tab_overlay_normal',
			[
				'label' => __('Normal', 'endless-addons'),
			]
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name'     => 'hover_overlay_normal',
				'label' => __('Background', 'endless-addons'),
				'show_label' => true,
				'types' => ['classic', 'gradient'],
				'exclude' => [
					'classic' => 'image'
				],
				'selector' => '{{WRAPPER}} .ea-logo-carousel-area, .ea-logo-carousel-area.style-three, .ea-logo-carousel-area.bg-color-f0fbf7, .ea-logo-carousel-area.style-eight',
			]
		);

		$this->end_controls_tab();

		$this->start_controls_tab(
			'_tab_overlay_hover',
			[
				'label' => __('Hover', 'endless-addons'),
			]
		);


		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name'     => 'hover_overlay_hover',
				'label' => __('Background', 'endless-addons'),
				'show_label' => true,
				'types' => ['classic', 'gradient'],
				'exclude' => [
					'classic' => 'image'
				],
				'selector' => '{{WRAPPER}} .ea-logo-carousel-area:hover, .ea-logo-carousel-area.style-three:hover, .ea-logo-carousel-area.bg-color-f0fbf7:hover, .ea-logo-carousel-area.style-eight:hover',
			]
		);

		$this->end_controls_tab();

		$this->end_controls_tabs();

		$this->end_controls_section();

	}

	/**
	 * Render Logo Carousel widget output on the frontend.
	 *
	 * Written in PHP and used to generate the final HTML.
	 *
	 * @since 1.0.5
	 * @access protected
	 */
	protected function render() {

		$settings = $this->get_settings_for_display(); 

		if( $settings['select_logo_carousel_style'] == 'style-01' ) :
        	$ea_logo_carousel_area = 'border-bottom pb-100';
        	$ea_logo_carousel_slider = 'ea-logo-carousel-slider';
        	$ea_single_logo_carousel = '';
        	$container = 'container';
        elseif( $settings['select_logo_carousel_style'] == 'style-02' ) :
        	$ea_logo_carousel_area = 'style-two ptb-100';
        	$ea_logo_carousel_slider = 'ea-logo-carousel-slider';
        	$ea_single_logo_carousel = 'style-two';
        	$container = 'container';
        elseif( $settings['select_logo_carousel_style'] == 'style-03' ) :
        	$ea_logo_carousel_area = 'style-three bg-color-191a28 ptb-100';
        	$ea_logo_carousel_slider = 'ea-logo-carousel-slider';
        	$ea_single_logo_carousel = 'style-three';
        	$container = 'container';
        elseif( $settings['select_logo_carousel_style'] == 'style-04' ) :
        	$ea_logo_carousel_area = 'ptb-100';
        	$ea_logo_carousel_slider = 'ea-logo-carousel-slider-four';
        	$ea_single_logo_carousel = 'style-four';
        	$container = 'container';
        elseif( $settings['select_logo_carousel_style'] == 'style-05' ) :
        	$ea_logo_carousel_area = 'bg-color-f0fbf7 ptb-100';
        	$ea_logo_carousel_slider = 'ea-logo-carousel-slider-five';
        	$ea_single_logo_carousel = 'style-five';
        	$container = 'container';
        elseif( $settings['select_logo_carousel_style'] == 'style-06' ) :
        	$ea_logo_carousel_area = 'style-six ptb-100';
        	$ea_logo_carousel_slider = 'ea-logo-carousel-slider-six';
        	$ea_single_logo_carousel = 'style-five';
        	$container = 'container-flu';
        elseif( $settings['select_logo_carousel_style'] == 'style-07' ) :
        	$ea_logo_carousel_area = 'style-seven pb-100';
        	$ea_logo_carousel_slider = 'ea-logo-carousel-slider-seven';
        	$ea_single_logo_carousel = 'style-seven';
        	$container = 'container';
        elseif( $settings['select_logo_carousel_style'] == 'style-08' ) :
        	$ea_logo_carousel_area = 'style-eight bg-color-f0f2f9 ptb-100';
        	$ea_logo_carousel_slider = 'ea-logo-carousel-slider-eight';
        	$ea_single_logo_carousel = 'style-eight';
        	$container = 'container';
        elseif( $settings['select_logo_carousel_style'] == 'style-09' ) :
        	$ea_logo_carousel_area = 'border-bottom pt-100 pb-70';
        	$container = 'container';
        elseif( $settings['select_logo_carousel_style'] == 'style-10' ) :
        	$ea_logo_carousel_area = 'style-ten bg-shape pt-100';
        	$ea_logo_carousel_slider = 'ea-logo-carousel-slider-ten';
        	$ea_single_logo_carousel = 'style-five';
        	$container = 'container';
        endif;

        if( $settings['select_logo_carousel_style'] == 'style-03' ) :
        	$white_title = 'white-title';
        else:
        	$white_title = '';
        endif;
        if($settings['select_logo_carousel_style'] == 'style-01' ) :
        	$white_logo = '';
        	$black_logo = 'white-logo';
        elseif($settings['select_logo_carousel_style'] == 'style-08' ) :
        	$white_logo = 'white-logo';
        	$black_logo = '';
        endif;

		if( $settings['show_logo_carousel'] == 'show' ) : ?>
			<!-- Start Logo Carousel Design Area -->
	        <div class="ea-logo-carousel-area <?php echo esc_attr($ea_logo_carousel_area); ?>">
	            <div class="<?php echo esc_attr($container); ?>">
	                <div class="section-title <?php echo esc_attr($white_title); ?>">
	                    <h2><?php echo esc_html__($settings['logo_carousel_title']); ?></h2>
	                    <p><?php echo wp_kses_post($settings['logo_carousel_desc']); ?></p>
	                </div>
                    <?php if( $settings['select_logo_carousel_style'] != 'style-09' ) : ?>
		                <div class="<?php echo esc_attr($ea_logo_carousel_slider); ?> owl-carousel owl-theme">
                            <?php if( $settings['select_logo_carousel_style'] == 'style-01' || $settings['select_logo_carousel_style'] == 'style-08' ) : ?>
			                	<?php foreach ( $settings['single_logo_carousel_image'] as $item ) : ?>
				                    <div class="ea-single-logo-carousel <?php echo esc_attr($ea_single_logo_carousel); ?>">
				                        <?php if( ! $item['logo_carousel_image']['url'] == '' ) : ?>
			                                <img src="<?php echo esc_url( $item['logo_carousel_image']['url'] ); ?>" class="<?php echo esc_attr($white_logo); ?>" alt="image">
		                                <?php endif; ?>
				                        <?php if( ! $item['logo_carousel_white_image']['url'] == '' ) : ?>
			                                <img src="<?php echo esc_url( $item['logo_carousel_white_image']['url'] ); ?>" class="<?php echo esc_attr($black_logo); ?>" alt="image">
		                                <?php endif; ?>
				                    </div>
			                    <?php endforeach;
			                else: 
			                	foreach ( $settings['logo_carousel_logos'] as $item ) : ?>
				                    <div class="ea-single-logo-carousel <?php echo esc_attr($ea_single_logo_carousel); ?>">
				                        <?php if( ! $item['url'] == '' ) : ?>
			                                <img src="<?php echo esc_url( $item['url'] ); ?>" alt="image">
		                                <?php endif; ?>
				                    </div>
			                    <?php endforeach;
		                    endif; ?>
		                </div>
		            <?php elseif( $settings['select_logo_carousel_style'] == 'style-09' ) : ?>
		            	<div class="row align-items-center">
		                    <div class="col-lg-6">
		                        <div class="ea-logo-content">
		                            <p><?php echo wp_kses_post($settings['logo_carousel_content']); ?></p>
		                        </div>
		                    </div>
		                    <div class="col-lg-6">
		                        <div class="row justify-content-center">
		                        	<?php foreach ( $settings['logo_carousel_logos'] as $image ) { ?>
                                        <div class="col-lg-4 col-sm-6">
                                        	<div class="single-logo">
	                                            <?php if($image['url'] != ''): ?>
	                                                <img src="<?php echo esc_url($image['url']); ?>" alt="Logo">
	                                            <?php endif; ?>
	                                        </div>
                                        </div>
                                    <?php } ?>
		                        </div>
		                    </div>
		                </div>
	                <?php endif; ?>
	            </div>
	        </div>
	        <!-- End Logo Carousel Design Area -->
        <?php endif;
    }

}
