<?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 insurance_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 'insurance-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__( 'Insurance 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(
            'ins_testimonial_opt',
            [
                'label' => __( 'Insurance Testimonial', 'ximsa' ),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
               
        $this->add_control(
			'sub_title',
			[
				'label' => esc_html__( 'Sub Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);
               
        $this->add_control(
			'title',
			[
				'label' => esc_html__( 'Title', 'ximsa' ),
				'type' => Controls_Manager::TEXT,
                'label_block' => true,
			]
		);

        $repeater = new Repeater();

		$repeater->add_control(
			'testimonial_img', [
				'label' => esc_html__( 'Testimonial Image', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'show_label' => true,
                'label_block' => true,
			]
		);
		$repeater->add_control(
			'testimonial_thumb', [
				'label' => esc_html__( 'Testimonial Thumb', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::MEDIA,
				'show_label' => true,
                'label_block' => true,
			]
		);
		$repeater->add_control(
			'featuresd_text', [
				'label' => esc_html__( 'Featured Text', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
                'label_block' => true,
			]
		);
		$repeater->add_control(
			'feedback', [
				'label' => esc_html__( 'Feedback', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXTAREA,
				'show_label' => true,
                'label_block' => true,
			]
		);
		$repeater->add_control(
			'rating',
			[
				'label' => esc_html__( 'Rating', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::NUMBER,
				'min' => 5,
				'max' => 5,
				'step' => .5,
			]
		);
		$repeater->add_control(
			'authore', [
				'label' => esc_html__( 'Atuhore', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
                'label_block' => true,
			]
		);
		$repeater->add_control(
			'designation', [
				'label' => esc_html__( 'Designation', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'show_label' => true,
                'label_block' => true,
			]
		);

		$this->add_control(
			'testimonials',
			[
				'label' => esc_html__( 'Add New Testimonial', 'ximsa' ),
				'type' => \Elementor\Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
				'title_field' => '{{{ authore }}}',
			]
		);
        
		$this->end_controls_section();

        $this->start_controls_section(
            'top_info_style',
            [
                'label' => __( 'About Style Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'sub_title_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Sub Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'sub_title_cl',
            [
                'label'     => esc_html__( 'Sub Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-five .title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'sub__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-five .title',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'main_title_st',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'main_title_cl',
            [
                'label'     => esc_html__( 'Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-five h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'main_title__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-five h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'feedback_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Feedback Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'feedbact_txt_cl',
            [
                'label'     => esc_html__( 'Feedback Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial-block-six .content-column .text' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'feedback_txt__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .testimonial-block-six .content-column .text',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'authore_txt_clo',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Authore Text Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'authore_color',
            [
                'label'     => esc_html__( 'Authore Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial-block-six .content-column .designation' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'authore__typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .testimonial-block-six .content-column .designation',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'authore_desig_clo',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Authore Designation Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );
        
        $this->add_control(
            'authore_desig_color',
            [
                'label'     => esc_html__( 'Authore Designation Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial-block-six .content-column .designation span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'authore_designation_typography',
                'label'          => esc_html__( 'Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .testimonial-block-six .content-column .designation span',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );

		$this->end_controls_section();
	}
		


	protected function render() {	
	$settings = $this->get_settings_for_display();?>        
    <!-- Testimonial Section Six -->
	<section class="testimonial-section-six">
		<div class="auto-container">
			<div class="sec-title-five centered">
				<div class="title"><?php echo esc_html($settings['sub_title']);?></div>
				<h2><?php echo esc_html($settings['title']);?></h2>
			</div>
			
			<div class="testimonial-outer">
            
            	<!-- Client Testimonial Carousel -->
                <div class="client-testimonial-carousel owl-carousel owl-theme">
					<?php foreach($settings['testimonials'] as $item):?>
					<!-- Testimonial Block Six -->
					<div class="testimonial-block-six">
						<div class="inner-box">
							<div class="row clearfix">
								<!-- Image Column -->
								<div class="image-column col-lg-5 col-md-12 col-sm-12">
									<div class="inner-column">
										<div class="image">
											<img src="<?php echo esc_url($item['testimonial_img']['url']);?>" alt="" />
										</div>
									</div>
								</div>
								<!-- Content Column -->
								<div class="content-column col-lg-7 col-md-12 col-sm-12">
									<div class="inner-column">
										<div class="title"><?php echo esc_html($item['featuresd_text']);?></div>
										<div class="text"><?php echo wp_kses( $item['feedback'], true );?></div>
										<div class="rating">
                                            <?php for($i = 0; $i < $item['rating']; $i++):?>
											<span class="fa fa-star"></span>
                                            <?php endfor;?>
										</div>
										<div class="designation"><?php echo esc_html($item['authore']);?>  <span>.  <?php echo esc_html($item['designation']);?></span></div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<?php endforeach;?>
				</div>
				
				<!-- Product Thumbs Carousel -->
                <div class="client-thumb-outer">
                    <div class="client-thumbs-carousel owl-carousel owl-theme">
                        <?php foreach($settings['testimonials'] as $item):?>
                        <div class="thumb-item">
                            <figure class="thumb-box"><img src="<?php echo esc_url($item['testimonial_thumb']['url']);?>" alt="<?php echo esc_attr($item['testimonial_thumb']['alt']);?>"></figure>
                        </div>
                        <?php endforeach;?>
                    </div>
                </div>
				
			</div>
			
		</div>
	</section>
	<!-- End Testimonial Section Six -->
    <?php  
    }
	
}

