<?php

/*
Widget Name: Testimonials Slider
Description: Display responsive touch friendly slider of testimonials from clients/customers.
Author: ThemesFlat
Author URI: https://www.themesflatthemes.com
*/
namespace ThemesflatAddons\Widgets;

use  Elementor\Repeater ;
use  Elementor\Controls_Manager ;
use  Elementor\Utils ;
use  Elementor\Scheme_Color ;
use  Elementor\Group_Control_Typography ;
use  Elementor\Scheme_Typography ;
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
// Exit if accessed directly
class TFL_Testimonials_Slider_Widget extends TFL_Widget_Base
{
    public function get_name()
    {
        return 'tfl-testimonials-slider';
    }
    
    public function get_title()
    {
        return __( 'Testimonials Slider', 'themesflat' );
    }
    
    public function get_icon()
    {
        return 'tfl-icon-testimonials1';
    }
    
    public function get_categories()
    {
        return array( 'themesflat-addons' );
    }
    
    public function get_custom_help_url()
    {
        return 'https://themesflatelementor.com/docs/themesflat-addons/core-addons/testimonials-addons/';
    }
    
    public function get_script_depends()
    {
        return [ 'jquery-flexslider', 'tfl-frontend-scripts', 'tfl-testimonials-slider-scripts' ];
    }
    
    public function get_style_depends()
    {
        return [
            'tfl-icomoon-styles',
            'tfl-flexslider-styles',
            'tfl-frontend-styles',
            'tfl-flexslider-custom-styles',
            'tfl-testimonials-slider-styles'
        ];
    }
    
    protected function register_controls()
    {
        $this->start_controls_section( 'section_testimonials_slider', [
            'label' => __( 'Testimonials Slider', 'themesflat' ),
        ] );
        $repeater = new Repeater();
        $repeater->add_control( 'client_name', [
            'label'       => __( 'Name', 'themesflat' ),
            'type'        => Controls_Manager::TEXT,
            'default'     => __( 'My client name', 'themesflat' ),
            'description' => __( 'The client or customer name for the testimonial', 'themesflat' ),
            'dynamic'     => [
            'active' => true,
        ],
        ] );
        $repeater->add_control( 'credentials', [
            'label'       => __( 'Client Details', 'themesflat' ),
            'type'        => Controls_Manager::TEXT,
            'description' => __( 'The details of the client/customer like company name, position held, company URL etc. HTML accepted.', 'themesflat' ),
            'dynamic'     => [
            'active' => true,
        ],
        ] );
        $repeater->add_control( 'client_image', [
            'label'       => __( 'Customer/Client Image', 'themesflat' ),
            'type'        => Controls_Manager::MEDIA,
            'default'     => [
            'url' => Utils::get_placeholder_image_src(),
        ],
            'label_block' => true,
            'dynamic'     => [
            'active' => true,
        ],
        ] );
        $repeater->add_control( 'testimonial_text', [
            'label'       => __( 'Testimonials Text', 'themesflat' ),
            'type'        => Controls_Manager::WYSIWYG,
            'description' => __( 'What your customer/client had to say', 'themesflat' ),
            'show_label'  => false,
            'dynamic'     => [
            'active' => true,
        ],
        ] );
        $this->add_control( 'testimonials', [
            'label'       => __( 'Testimonials', 'themesflat' ),
            'type'        => Controls_Manager::REPEATER,
            'default'     => [ [
            'client_name'      => __( 'Customer #1', 'themesflat' ),
            'credentials'      => __( 'CEO, Invision Inc.', 'themesflat' ),
            'testimonial_text' => __( 'I am testimonial text. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat' ),
        ], [
            'client_name'      => __( 'Customer #2', 'themesflat' ),
            'credentials'      => __( 'Lead Developer, Automattic Inc', 'themesflat' ),
            'testimonial_text' => __( 'I am testimonial text. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat' ),
        ], [
            'client_name'      => __( 'Customer #3', 'themesflat' ),
            'credentials'      => __( 'Store Manager, Walmart Inc', 'themesflat' ),
            'testimonial_text' => __( 'I am testimonial text. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat' ),
        ] ],
            'fields'      => $repeater->get_controls(),
            'title_field' => '{{{ client_name }}}',
        ] );

        $this->end_controls_section();
        $this->start_controls_section( 'section_settings', [
            'label' => __( 'Slider Settings', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_SETTINGS,
        ] );

        $this->add_control('style', [
            'type' => Controls_Manager::SELECT,
            'label' => __('Choose Style', 'themesflat'),
            'default' => 'style1',
            'options' => [
                'style1' => __('Style 1', 'themesflat'),
                'style2' => __('Style 2', 'themesflat'),
                'style3' => __('Style 3', 'themesflat'),
                'style4' => __('Style 4', 'themesflat'),
            ],
        ]);


        $this->add_control( 'slide_animation', [
            'label'   => __( 'Animation', 'themesflat' ),
            'type'    => Controls_Manager::SELECT,
            'default' => 'slide',
            'options' => [
            'slide' => __( 'Slide', 'themesflat' ),
            'fade'  => __( 'Fade', 'themesflat' ),
        ],
        ] );

        $this->add_control( 'slideshow_speed', [
            'label'   => __( 'Slideshow Speed', 'themesflat' ),
            'type'    => Controls_Manager::NUMBER,
            'default' => 5000,
        ] );
        $this->add_control( 'animation_speed', [
            'label'   => __( 'Animation Speed', 'themesflat' ),
            'type'    => Controls_Manager::NUMBER,
            'default' => 600,
        ] );
        $this->add_control( 'pause_on_hover', [
            'type'         => Controls_Manager::SWITCHER,
            'label_off'    => __( 'No', 'themesflat' ),
            'label_on'     => __( 'Yes', 'themesflat' ),
            'return_value' => 'yes',
            'separator'    => 'before',
            'default'      => 'yes',
            'label'        => __( 'Pause on Hover?', 'themesflat' ),
            'description'  => __( 'Should the slider pause on mouse hover over the slider.', 'themesflat' ),
        ] );
        $this->add_control( 'pause_on_action', [
            'type'         => Controls_Manager::SWITCHER,
            'label_off'    => __( 'No', 'themesflat' ),
            'label_on'     => __( 'Yes', 'themesflat' ),
            'return_value' => 'yes',
            'default'      => 'no',
            'label'        => __( 'Pause slider on action?', 'themesflat' ),
            'description'  => __( 'Should the slideshow pause once user initiates an action using navigation/direction controls.', 'themesflat' ),
        ] );
        $this->add_control( 'smooth_height', [
            'type'         => Controls_Manager::SWITCHER,
            'label_off'    => __( 'No', 'themesflat' ),
            'label_on'     => __( 'Yes', 'themesflat' ),
            'return_value' => 'yes',
            'default'      => 'no',
            'label'        => __( 'Smooth Height?', 'themesflat' ),
            'description'  => __( 'Animate the height of the slider smoothly for slides of varying height.', 'themesflat' ),
        ] );

        $this->end_controls_section();

//        general
        $this->start_controls_section( 'section_testimonials_general', [
            'label' => __( 'General', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'bg_color', [
            'label'     => __( 'Background Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style1 .tfl-testimonial .tfl-testimonial-text,
                {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .tfl-testimonial,
                {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .tfl-testimonial,
                {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style2 .tfl-testimonial .tfl-testimonial-text' => 'background: {{VALUE}};',
            ],
        ] );

        $this->end_controls_section();







        $this->start_controls_section( 'section_testimonials_avatar', [
            'label' => __( 'Author Image', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );


        $this->add_responsive_control( 'avatar_size', [
            'label'   => __( 'Avatar Size', 'themesflat' ),
            'type'       => Controls_Manager::SLIDER,
            'size_units' => [ 'px' ],
            'default'    => [
                'size' => 60,
            ],
            'range'      => [
                'px' => [
                    'min' => 0,
                    'max' => 200,
                ],
            ],
            'selectors'  => [
                '{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .avatar,{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .avatar ' => 'width: {{SIZE}}{{UNIT}};',
                '{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .avatar,{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .avatar'  => 'height:  {{SIZE}}{{UNIT}};',
            ],
        ] );

        $this->add_responsive_control(
            'avatar_border_radius',
            [
                'label' => esc_html__( 'Border Radius', 'themesflat-addons' ),
                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', 'em', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .avatar,
                    {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .avatar ' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->end_controls_section();










//        text
        $this->start_controls_section( 'section_testimonials_text', [
            'label' => __( 'Author Text', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'text_color', [
            'label'     => __( 'Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-testimonials-slider .tfl-testimonial-text,
            {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .tfl-testimonial .tfl-text,
            {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .tfl-testimonial .tfl-text' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'text_typography',
            'selector' => '{{WRAPPER}} .tfl-testimonials-slider .tfl-testimonial-text,
            {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .tfl-testimonial .tfl-text,
            {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .tfl-testimonial .tfl-text',
        ] );
        $this->end_controls_section();

//        name
        $this->start_controls_section( 'section_testimonials_name', [
            'label' => __( 'Author Name', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'name_color', [
            'label'     => __( 'Name Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style2 .tfl-testimonial .tfl-testimonial-text .tfl-author-name,
                {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style1 .tfl-testimonial .tfl-testimonial-text .tfl-author-name,
                {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .tfl-testimonial .tfl-testimonial-text .tfl-author-name,
                {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .tfl-testimonial-text .tfl-author-name' => 'color: {{VALUE}};',
            ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'name_typography',
            'selector' => '{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style2 .tfl-testimonial .tfl-testimonial-text .tfl-author-name,
            {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .tfl-testimonial .tfl-testimonial-text .tfl-author-name,
            {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .tfl-testimonial .tfl-testimonial-text .tfl-author-name,
            {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style1 .tfl-testimonial .tfl-testimonial-text .tfl-author-name',
        ] );

        $this->end_controls_section();

//        position
        $this->start_controls_section( 'section_testimonials_position', [
            'label' => __( 'Author Position', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
            $this->add_control( 'position_color', [
                'label'     => __( 'Position Color', 'themesflat' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style1 .tfl-testimonial .tfl-testimonial-text .tfl-author-credentials,
                    {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .tfl-testimonial .tfl-testimonial-text .tfl-author-credentials,
                    {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .tfl-testimonial .tfl-testimonial-text .tfl-author-credentials,
                    {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style2 .tfl-testimonial .tfl-testimonial-text .tfl-author-credentials' => 'color: {{VALUE}};',
                ],
            ] );
            $this->add_group_control( Group_Control_Typography::get_type(), [
                'name'     => 'position_typography',
                'selector' => '{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style1 .tfl-testimonial .tfl-testimonial-text .tfl-author-credentials,
                {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .tfl-testimonial .tfl-testimonial-text .tfl-author-credentials,
                {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .tfl-testimonial .tfl-testimonial-text .tfl-author-credentials,
                {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style2 .tfl-testimonial .tfl-testimonial-text .tfl-author-credentials',
            ] );
        $this->end_controls_section();

//        dot and narrow
        $this->start_controls_section( 'section_testimonials_dots_arrow', [
            'label' => __( 'Dots and Arrow', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );

            $this->add_control( 'dots_normal', [
                'label'     => __( 'Normal', 'themesflat' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .tfl-flex-control-nav li a:after,
                    {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .tfl-flex-control-nav li a:after' => 'background: {{VALUE}};',
                    '{{WRAPPER}} .tfl-testimonials-slider.tfl-container .tfl-flex-direction-nav a' => 'color: {{VALUE}};',
                ],
            ] );

            $this->add_control( 'dots_active', [
                'label'     => __( 'Active', 'themesflat' ),
                'type'      => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .tfl-flex-control-nav li a.tfl-flex-active,
                    {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .tfl-flex-control-nav li a:hover,
                    {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .tfl-flex-control-nav li a.tfl-flex-active,
                    {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .tfl-flex-control-nav li a:hover' => 'border: 1px solid {{VALUE}};',

                    '{{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .tfl-flex-control-nav li a.tfl-flex-active:after,
                    {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style4 .tfl-flex-control-nav li a:hover:after,
                    {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .tfl-flex-control-nav li a.tfl-flex-active:after,
                    {{WRAPPER}} .tfl-testimonials-slider.tfl-testimonials-style-style3 .tfl-flex-control-nav li a:hover:after ' => 'background: {{VALUE}};',
                ],
            ] );

        $this->end_controls_section();

    }
    
    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $settings['slider_id'] = $this->get_id();
        $settings['control_nav'] = 'yes';
        $settings['direction_nav'] = 'no';
        $settings['title_tag'] = 'h4';
        $settings = apply_filters( 'tfl_testimonials_slider_' . $this->get_id() . '_settings', $settings );
        $args['settings'] = $settings;
        $args['widget_instance'] = $this;
        tfl_get_template_part( 'addons/testimonials-slider/loop', $args );
    }
    
    protected function content_template()
    {
    }

}