<?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\Plugin;

/**
 * Elementor button widget.
 * Elementor widget that displays a button with the ability to control every
 * aspect of the button design.
 *
 * @since 1.0.0
 */
class digpay_testimonials extends Widget_Base {

    /**
     * Get widget name.
     * Retrieve button widget name.
     *
     * @since  1.0.0
     * @access public
     * @return string Widget name.
     */
    public function get_name() {
        return 'digpay_testimonials';
    }

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

    /**
     * Get widget icon.
     * Retrieve button widget icon.
     *
     * @since  1.0.0
     * @access public
     * @return string Widget icon.
     */
    public function get_icon() {
        return 'eicon-library-open';
    }

    /**
     * Get widget categories.
     * Retrieve the list of categories the button widget belongs to.
     * Used to determine where to display the widget in the editor.
     *
     * @since  2.0.0
     * @access public
     * @return array Widget categories.
     */
    public function get_categories() {
        return [ 'ximsa' ];
    }

    /**
     * Register button 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(
            'digital_card_test',
            [
                'label' => esc_html__( 'Digital Pay Testimonial', 'ximsa' ),
            ]
        );
		$this->add_control(
			'subtitle',
			[
				'label'       => __( 'Sub Title', 'ximsa' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Sub Title', 'ximsa' ),
			]
		);
		$this->add_control(
			'title',
			[
				'label'       => __( 'Title', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Title', 'ximsa' ),
			]
		);
		$this->add_control(
			'description',
			[
				'label'       => __( 'Title', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => __( 'Enter your Title', 'ximsa' ),
			]
		);
		
		$repeater = new \Elementor\Repeater();

        $repeater->add_control(
			'authore_img',
			[
				'label'       => __( 'Authore Image', 'ximsa' ),
				'type'        => Controls_Manager::MEDIA,
				'dynamic'     => [
					'active' => true,
				],
			]
		);
        $repeater->add_control(
			'feedback',
			[
				'label'       => __( 'Feedback', 'ximsa' ),
				'type'        => Controls_Manager::TEXTAREA,
				'dynamic'     => [
					'active' => true,
				],
			]
		);
        $repeater->add_control(
			'authore_name',
			[
				'label'       => __( 'Authore Name', 'ximsa' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
			]
		);
        $repeater->add_control(
			'designation',
			[
				'label'       => __( 'Designation', 'ximsa' ),
				'type'        => Controls_Manager::TEXT,
				'dynamic'     => [
					'active' => true,
				],
			]
		);
        
        $this->add_control(
			'testimonials',
			[
				'label' => esc_html__( 'Testimonials', 'ximsa' ),
				'type' => Controls_Manager::REPEATER,
				'fields' => $repeater->get_controls(),
                'title_field' => '{{{ authore_name }}}',
			]
		);
		
		$this->end_controls_section();
        $this->start_controls_section(
            'testimonial_info_st',
            [
                'label' => __( 'Testimonials Style Settings', 'ximsa' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_control(
            'fs_sub_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Sub Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'fs_sub_title_cl',
            [
                'label'     => esc_html__( 'Sub Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-three .title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'fs_sth_typography',
                'label'          => esc_html__( 'Sub Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-three .title',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'fs_title_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Feature Title Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'fs_title_cl',
            [
                'label'     => esc_html__( 'Feature Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-three h2' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'feature_title_typography',
                'label'          => esc_html__( 'Feature Title Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-three h2',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'fs_reg_title_cl',
            [
                'label'     => esc_html__( 'Feature Reguler Title Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-three h2 span' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'feature_reg_title_typography',
                'label'          => esc_html__( 'Feature Reguler Title Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-three h2 span',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'desc_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Desc Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'fs_desc_cl',
            [
                'label'     => esc_html__( 'Description Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .sec-title-three .text' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'desc_s_typography',
                'label'          => esc_html__( 'Feature Title Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .sec-title-three .text',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'testimonial_auth_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Authore Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'fs_auth_cl',
            [
                'label'     => esc_html__( 'Authore Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial-block-five h5' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'authore_typography',
                'label'          => esc_html__( 'Authore Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .testimonial-block-five h5',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'testimonial_feeb_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Feedback Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'fs_feedback_cl',
            [
                'label'     => esc_html__( 'Feedback Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial-block-five .content .text' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'feedback_typography',
                'label'          => esc_html__( 'Feeedback Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .testimonial-block-five .content .text',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'testimonial_desgi_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Designation Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'fs_designation_cl',
            [
                'label'     => esc_html__( 'Designation Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial-block-five .designation' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name'           => 'desig_typography',
                'label'          => esc_html__( 'Desig Typography', 'ximsa' ),
                'selector'       => '{{WRAPPER}} .testimonial-block-five .designation',
                'fields_options' => [
                    'typography' => [
                        'default' => 'custom',
                    ],
                ],
            ]
        );
        $this->add_control(
            'testimonial_dot_style',
            [
                'type'      => Controls_Manager::HEADING,
                'label'     => esc_html__( 'Dot Active Style', 'ximsa' ),
                'separator' => 'before',
            ]
        );  
        $this->add_control(
            'fs_dot_cl',
            [
                'label'     => esc_html__( 'Dot Active Color', 'ximsa' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial-section-five .carousel-column .owl-dots .owl-dot.active, .testimonial-section-five .carousel-column .owl-dots .owl-dot:hover' => 'background-color: {{VALUE}} ',
                ],
            ]
        );
        
        $this->end_controls_section();
    }
    /**
     * Render button widget output on the frontend.
     * Written in PHP and used to generate the final HTML.
     *
     * @since  1.0.0
     * @access protected
     */
    protected function render() {
        $settings = $this->get_settings_for_display();
        $allowed_tags = wp_kses_allowed_html('post');
    ?>
      <!-- Testimonial Section Five -->
        <section class="testimonial-section-five">
            <div class="auto-container">
                <div class="row clearfix">
                
                    <!-- Title Column -->
                    <div class="title-column col-lg-6 col-md-12 col-sm-12">
                        <div class="inner-column">
                            <div class="sec-title-three">
                                <div class="title"><?php echo esc_html($settings['subtitle']);?></div>
                                <h2><?php echo wp_kses( $settings['title'], true );?></h2>
                                <div class="text"><?php echo wp_kses( $settings['description'], true );?></div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- Carousel Column -->
                    <div class="carousel-column col-lg-6 col-md-12 col-sm-12">
                        <div class="inner-column">
                            <div class="testimonial-carousel-three owl-carousel owl-theme">
                                <?php foreach($settings['testimonials'] as $item):?>
                                <!-- Testimonial Block Five -->
                                <div class="testimonial-block-five">
                                    <div class="inner-box">
                                        <div class="author-image">
                                            <img src="<?php echo esc_url($item['authore_img']['url']);?>" alt="" />
                                        </div>
                                        <div class="content">
                                            <div class="text"><?php echo esc_html($item['feedback']);?></div>
                                            <h5><?php echo esc_html($item['authore_name']);?></h5>
                                            <div class="designation"><?php echo esc_html($item['designation']);?></div>
                                            <span class="quote-icon flaticon-left-quotes-sign"></span>
                                        </div>
                                    </div>
                                </div>
                                <?php endforeach;?>
                            </div>
                        </div>
                    </div>
                    
                </div>
            </div>
        </section>
        <!-- End Testimonial Section Five -->
 
        <?php
    }
}
