<?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 saas_testimonial 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 'saas-testimonial';
	}

	/**
	 * Get widget title.
	 *
	 * Retrieve Elementor widget title.
	 *
	 * @since 1.0.0
	 * @access public
	 *
	 * @return string Widget title.
	 */
	public function get_title() {
		return esc_html__( 'Saas Testimonial', '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(
            'saas_testimonial_options',
            [
                'label' => __( 'Saas Testimonial Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
			'shape1',
			[
				'label' => esc_html__( 'Shape 1', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape2',
			[
				'label' => esc_html__( 'Shape 2', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape3',
			[
				'label' => esc_html__( 'Map Shape', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape4',
			[
				'label' => esc_html__( 'Dot 1', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape5',
			[
				'label' => esc_html__( 'Dot 2', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape6',
			[
				'label' => esc_html__( 'Dot 3', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape7',
			[
				'label' => esc_html__( 'Dot 4', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape8',
			[
				'label' => esc_html__( 'Dot 5', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape9',
			[
				'label' => esc_html__( 'Dot 6', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape10',
			[
				'label' => esc_html__( 'Dot 7', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'shape11',
			[
				'label' => esc_html__( 'Dot 8', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'thumbs',
			[
				'label' => esc_html__( 'Thumb Items', 'ximsa' ),
				'type' => Controls_Manager::GALLERY,
                'label_block' => true,
			]
		);
        
        
        $this->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
				'default' => esc_html__( 'Grow your Business
                Real, Organic & Automatic', 'ximsa' ),
				'placeholder' => esc_html__( 'Type Banner Title Here', 'ximsa' ),
                'label_block' => true,
			]
		);
        $this->add_control(
			'rating',
			[
				'label' => esc_html__( 'Rating', 'ximsa' ),
				'type' => Controls_Manager::NUMBER,
				'min' => 0,
				'max' => 5,
				'step' => 1,
			]
		);
        
        $repeater = new \Elementor\Repeater();        
        $repeater->add_control(
			'is_active',
			[
				'label' => esc_html__( 'Is Active', 'ximsa' ),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'Show', 'ximsa' ),
				'label_off' => esc_html__( 'Hide', 'ximsa' ),
				'return_value' => 'yes',
				'default' => 'no',
			]
		);
        $repeater->add_control(
			'authore_img',
			[
				'label' => esc_html__( 'Authore Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'feedback',
			[
				'label' => esc_html__( 'Authore Feedbacl', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'name',
			[
				'label' => esc_html__( 'Authore Name', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'designation',
			[
				'label' => esc_html__( 'Authore Designation', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
			]
		);
        
        $this->add_control(
			'testimonials',
			[
				'label' => esc_html__( 'Add List Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ name }}}',
			]
		);
		
		$this->end_controls_section();
        $this->start_controls_section(
            'slider_settings_style',
            [
                'label' => __( 'Banner Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
			'container_width',
			[
				'label' => esc_html__( 'Container Width', 'plugin-name' ),
				'type' => \Elementor\Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 2000,
						'step' => 1,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				
				'selectors' => [
					'{{WRAPPER}} .container' => 'max-width: {{SIZE}}{{UNIT}};',
				],
			]
		);
        $this->add_control(
            'slider_title',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'sl_title_cl',
            [
                'label'     => esc_html__( 'Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-saas-section-title h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'sl_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-saas-section-title h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'rating_color',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Rating Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'rating_cl',
            [
                'label'     => esc_html__( 'Rating Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-saas-testimonial-ratting li' => 'color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->add_control(
            'authore_name_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Authore Name Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'authore_name',
            [
                'label'     => esc_html__( 'Authore Name Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-sass-testimonial-inner-item .xis-sass-author h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'authore_name_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-sass-testimonial-inner-item .xis-sass-author h3',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'authore_des_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Authore Designation Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'desig_name',
            [
                'label'     => esc_html__( 'Authore Designation Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-sass-testimonial-inner-item .xis-sass-author span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'authore_desig_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-sass-testimonial-inner-item .xis-sass-author span',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'authore_feedback_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Authore Feedback Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'fdb_name',
            [
                'label'     => esc_html__( 'Authore Feedback Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-sass-testimonial-inner-item .xis-sass-testi-text p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'authore_feedback_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-sass-testimonial-inner-item .xis-sass-testi-text p',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'nav_active_cl',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Nav Active Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'nav_active_bg',
				'label' => esc_html__( 'Background', 'plugin-name' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-saas-testimonial-content .carousel-control-next:before, .xis-saas-testimonial-content .carousel-control-prev:before',
			]
		);
		$this->end_controls_section();
        
	}
		


	protected function render() {	
	$settings = $this->get_settings_for_display();?>        
	<!-- Start of Testimonial section
	============================================= -->
	<section id="xis-saas-testimonial" class="xis-saas-testimonial-section position-relative">
		<span class="xis-saas-testi-shape1 position-absolute"><img src="<?php echo esc_url($settings['shape1']['url']);?>"></span>
		<span class="xis-saas-testi-shape2 position-absolute"><img src="<?php echo esc_url($settings['shape2']['url']);?>"></span>
		<div class="container">
			<div class="xis-saas-section-title text-center xis-saas-headline">
				<h2><?php echo esc_html($settings['title']);?></h2>
			</div> 
			<div class="xis-saas-testimonial-ratting ul-li text-center">
				<ul>
                    <?php for($i = 0; $i < $settings['rating']; $i++):?>
					    <li><i class="fas fa-star"></i></li>
                    <?php endfor;?>
				</ul>
			</div>
			<div class="xis-saas-testimonial-content position-relative">
				<span class="xis-saas-testi-bg position-absolute"><img src="<?php echo esc_url($settings['shape3']['url']);?>"></span>
				<span class="xis-saas-testi-circle1 position-absolute"><img src="<?php echo esc_url($settings['shape4']['url']);?>" alt=""></span>
				<span class="xis-saas-testi-circle2 position-absolute"><img src="<?php echo esc_url($settings['shape5']['url']);?>" alt=""></span>
				<span class="xis-saas-testi-circle3 position-absolute"><img src="<?php echo esc_url($settings['shape6']['url']);?>" alt=""></span>
				<span class="xis-saas-testi-circle4 position-absolute"><img src="<?php echo esc_url($settings['shape7']['url']);?>" alt=""></span>
				<span class="xis-saas-testi-circle5 position-absolute"><img src="<?php echo esc_url($settings['shape8']['url']);?>" alt=""></span>
				<span class="xis-saas-testi-circle6 position-absolute"><img src="<?php echo esc_url($settings['shape9']['url']);?>" alt=""></span>
				<span class="xis-saas-testi-circle7 position-absolute"><img src="<?php echo esc_url($settings['shape10']['url']);?>" alt=""></span>
				<span class="xis-saas-testi-circle8 position-absolute"><img src="<?php echo esc_url($settings['shape11']['url']);?>" alt=""></span>
				<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
					<div class="xis-saas-testimonial-slider-wrapper">
						<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
							<div class="carousel-indicators">

                                <?php $i = 0; foreach($settings['thumbs'] as $thumb): $i++;?>
								<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="<?php echo esc_attr($i);?>" class="active" aria-current="true" aria-label="Slide <?php echo esc_attr($i);?>1">
									<img src="<?php echo esc_url($thumb['url']);?>" alt="">
								</button>
								<?php endforeach;?>

							</div>
							<div class="carousel-inner">
                                <?php foreach($settings['testimonials'] as $item):?>
								<div class="carousel-item <?php if($item['is_active'] == 'yes'){ echo esc_attr('active');}?>">
									<div class="xis-sass-testimonial-inner-item text-center">
										<div class="xis-sass-author-img-wrapper position-relative">
											<div class="xis-sass-author-img position-relative d-flex align-items-center justify-content-center">
												<img src="<?php echo esc_url($item['authore_img']['url']);?>" alt="<?php echo esc_url($item['authore_img']['alt']);?>">
											</div>
										</div>
										<div class="xis-sass-testi-text pera-content position-relative">
											<p><?php echo wp_kses( $item['feedback'], true );?></p>
											<div class="xis-sass-author  xis-saas-headline"> 
												<h3 class="xis-sass-name"><?php echo wp_kses( $item['name'], true );?></h3>
												<span><?php echo wp_kses( $item['designation'], true );?></span>
											</div>
										</div>
									</div>
								</div>
                                <?php endforeach;?>
							</div>
							<div class="xis-sass-testimonial-carousel-icon d-flex justify-content-center  position-absolute">
								<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="prev">
									<span class="carousel-control-prev-icon" aria-hidden="true"><i class="far fa-arrow-left"></i></span>
								</button>
								<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide="next">
									<span class="carousel-control-next-icon" aria-hidden="true"><i class="far fa-arrow-right"></i></span>
								</button>
							</div>	
						</div>
					</div>
				</div>
			</div>
		</div>
	</section>		
<!-- End of Testimonial section
	============================================= -->	
    <?php  
    }
	
}

