<?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 dgi_testimonials_widget 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 'dgi-testimonial-item';
	}

	/**
	 * 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 Agency 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(
            'testimonial_sec_options',
            [
                'label' => __( 'Testimonial Section Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
			'shape',
			[
				'label' => esc_html__( 'Shape', '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(
			'sub_title',
			[
				'label' => esc_html__( 'Sub Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Online Payments', 'ximsa' ),
				'placeholder' => esc_html__( 'Type Banner Sub Title Here', 'ximsa' ),
                'label_block' => true,
			]
		);
        $this->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Looking to take online payments?', 'ximsa' ),
				'placeholder' => esc_html__( 'Type Banner Title Here', 'ximsa' ),
                'label_block' => true,
			]
		);
        $this->add_control(
			'circle1',
			[
				'label' => esc_html__( 'Circle 1', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'circle2',
			[
				'label' => esc_html__( 'Circle 2', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'circle3',
			[
				'label' => esc_html__( 'Circle 3', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'circle4',
			[
				'label' => esc_html__( 'Circle 4', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->end_controls_section();
        $this->start_controls_section(
            'testimonial__options',
            [
                'label' => __( 'Testimonial Options', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
			'thumb1',
			[
				'label' => esc_html__( 'Thumb1', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'thumb2',
			[
				'label' => esc_html__( 'Thumb2', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'thumb3',
			[
				'label' => esc_html__( 'Thumb3', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'thumb4',
			[
				'label' => esc_html__( 'Thumb4', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'thumb5',
			[
				'label' => esc_html__( 'Thumb5', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $this->add_control(
			'thumb6',
			[
				'label' => esc_html__( 'Thumb6', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater = new \Elementor\Repeater();
        $repeater->add_control(
			'authore_image',
			[
				'label' => esc_html__( 'Authore Image', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'authore_quote',
			[
				'label' => esc_html__( 'Authore Quote', 'ximsa' ),
				'type' => Controls_Manager::MEDIA,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'authore_name',
			[
				'label' => esc_html__( 'Authore Name', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
        $repeater->add_control(
			'designation',
			[
				'label' => esc_html__( 'Designation', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
			]
		);
        $repeater->add_control(
			'feedback',
			[
				'label' => esc_html__( 'Feedback', 'ximsa' ),
				'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
			]
		);

        $this->add_control(
			'testimonials',
			[
				'label' => esc_html__( 'Add Testimonials Item', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ authore_name }}}',
			]
		);
		$this->end_controls_section();

        $this->start_controls_section(
            'feature_style',
            [
                'label' => __( 'Feature Style Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'se__sub_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Sub Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
			Group_Control_Background::get_type(),
			[
				'name' => 'sub_bgbackground',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-dia-section-title span',
			]
		);
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'se_sth_typography',
                'label'          => esc_html__( 'Sub Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-dia-section-title span',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'se_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'se_ht_color',
            [
                'label'     => esc_html__( 'Heading Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dia-section-title h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'se_th_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .xis-dia-section-title h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'tst_title_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Testimonial Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'tst_title_cl',
            [
                'label'     => esc_html__( 'Testimonial Name Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dia-testimonial-inner-item .xis-dia-testi-text .xis-dia-author h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tst_name_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-dia-testimonial-inner-item .xis-dia-testi-text .xis-dia-author h3
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'test_fbk_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Testimonial Feedback Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'test_name_cl',
            [
                'label'     => esc_html__( 'Authore Name Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-testi-slide-item .xis-testi-text h3' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tst_fet_title_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-testi-slide-item .xis-testi-text h3
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'deg_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Designation Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'test_deg_cl',
            [
                'label'     => esc_html__( 'Authore Designation Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dia-testimonial-inner-item .xis-dia-testi-text .xis-dia-author span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tst_deg_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-dia-testimonial-inner-item .xis-dia-testi-text .xis-dia-author span
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'fedback_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Feedback Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'test_fdbk_cl',
            [
                'label'     => esc_html__( 'Authore Feedback Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .xis-dia-testimonial-inner-item .xis-dia-testi-text p' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'tst_fedback_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '
                    {{WRAPPER}} .xis-dia-testimonial-inner-item .xis-dia-testi-text p
                ',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'quote_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Quote Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'quote_test_background',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '{{WRAPPER}} .xis-dia-testimonial-inner-item .xis-dia-quote',
			]
		);
        $this->add_control(
            'nav_bar_cl',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Nav Bar Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			[
				'name' => 'nav_background',
				'label' => esc_html__( 'Background', 'ximsa' ),
				'types' => [ 'gradient' ],
				'selector' => '
					{{WRAPPER}} .xis-dia-testimonial-content .carousel-control-next:before,
					{{WRAPPER}} .xis-dia-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-dia-testimonial" class="xis-dia-testimonial-section position-relative">
		<span class="xis-dia-testi-side-shape1 position-absolute"><img src="<?php echo esc_url($settings['shape']['url']);?>" alt=""></span>
		<span class="xis-dia-testi-side-shape2 position-absolute"><img src="<?php echo esc_url($settings['shape2']['url']);?>" alt=""></span>
		<div class="container">
			<div class="xis-dia-section-title xis-dia-headline text-center">
				<span><?php echo esc_html($settings['sub_title']);?></span>
				<h2><?php echo esc_html($settings['title']);?></h2>
			</div>
			<div class="xis-dia-testimonial-content position-relative">
				<span class="xis-dia-testi-circle1 position-absolute"><img src="<?php echo esc_url($settings['circle1']['url']);?>" alt=""></span>
				<span class="xis-dia-testi-circle2 position-absolute"><img src="<?php echo esc_url($settings['circle2']['url']);?>" alt=""></span>
				<span class="xis-dia-testi-circle3 position-absolute"><img src="<?php echo esc_url($settings['circle3']['url']);?>" alt=""></span>
				<span class="xis-dia-testi-circle4 position-absolute"><img src="<?php echo esc_url($settings['circle4']['url']);?>" alt=""></span>

				<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
					<div class="carousel-indicators">
						<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1">
							<img src="<?php echo esc_url($settings['thumb1']['url']);?>" alt="">
						</button>
						<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="1" aria-label="Slide 2">
							<img src="<?php echo esc_url($settings['thumb2']['url']);?>" alt="">
						</button>
						<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="2" aria-label="Slide 3">
							<img src="<?php echo esc_url($settings['thumb3']['url']);?>" alt="">
						</button>
						<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="3" aria-label="Slide 4">
							<img src="<?php echo esc_url($settings['thumb4']['url']);?>" alt="">
						</button>
						<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="4" aria-label="Slide 5">
							<img src="<?php echo esc_url($settings['thumb5']['url']);?>" alt="">
						</button>
						<button type="button" data-bs-target="#carouselExampleCaptions" data-bs-slide-to="5" aria-label="Slide 6">
							<img src="<?php echo esc_url($settings['thumb6']['url']);?>" alt="">
						</button>
					</div>
					<div class="carousel-inner">
                        <?php $i = 0; foreach($settings['testimonials'] as $item): $i++?>
						<div class="carousel-item <?php if($i == 1){ echo esc_attr('active');}?>">
							<div class="xis-dia-testimonial-inner-item text-center">
								<div class="xis-dia-author-img-wrapper position-relative">
									<div class="xis-dia-author-img">
										<img src="<?php echo esc_url($item['authore_image']['url']);?>" alt="">
									</div>
									<div class="xis-dia-quote position-absolute">
										<img src="<?php echo esc_url($item['authore_quote']['url']);?>" alt="">
									</div>
								</div>
								<div class="xis-dia-testi-text pera-content xis-dia-headline">
									<p><?php echo __($item['feedback']);?></p>
									<div class="xis-dia-author">
										<h3 class="xis-dia-name"><?php echo esc_html($item['authore_name']);?></h3>
										<span><?php echo esc_html($item['designation']);?></span>
									</div>
								</div>
							</div>
						</div>
                        <?php endforeach;?>
					</div>
					<div class="xis-dia-testimonial-carousel-icon d-flex justify-content-center  position-relative">
						<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>
	</section>
<!-- End of Testimonial section
	============================================= -->
    <?php
    }



}
