<?php

/*
Widget Name: Testimonials
Description: Display testimonials from your clients/customers in a multi-column grid.
Author: ThemesFlat
Author URI: https://www.themesflatthemes.com
*/
namespace ThemesflatAddons\Widgets;

use  Elementor\Repeater ;
use  Elementor\Widget_Base ;
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_Widget extends TFL_Widget_Base
{
    public function get_name()
    {
        return 'tfl-testimonials';
    }
    
    public function get_title()
    {
        return __( 'Testimonials', 'themesflat' );
    }
    
    public function get_icon()
    {
        return 'tfl-icon-testimonials3';
    }
    
    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 [ 'tfl-waypoints', 'tfl-frontend-scripts' ];
    }
    
    public function get_style_depends()
    {
        return [ 'tfl-animate-styles', 'tfl-frontend-styles', 'tfl-testimonials-styles' ];
    }
    
    protected function register_controls()
    {
        $this->start_controls_section( 'section_testimonials', [
            'label' => __( 'Testimonials', '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, credential 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,
        ],
        ] );
        $repeater->add_control( "widget_animation", [
            "type"    => Controls_Manager::SELECT,
            "label"   => __( "Animation Type", "themesflat" ),
            'options' => tfl_get_animation_options(),
            'default' => 'none',
            'dynamic' => [
            'active' => true,
        ],
        ] );
        $this->add_control( 'testimonials', [
            'label'       => __( 'Testimonials', 'themesflat' ),
            'type'        => Controls_Manager::REPEATER,
            'separator'   => 'before',
            '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->add_control( 'upgrade_notice', [
            'type'      => Controls_Manager::RAW_HTML,
            'separator' => 'before',
            'raw'       => '<div style="text-align:center;line-height:1.6;"><p>' . __( 'Unlock new possibilities with premium widgets and styles of <strong>Themesflat Addons for Elementor <i>Premium</i></strong>. ', 'themesflat' ) . '</p><p style="padding-top:15px;"><a class="elementor-button elementor-button-default elementor-button-go-pro" href="https://themesflatelementor.com/pricing/#pricing-plans" target="_blank"><i class="fa fa-hand-o-right" aria-hidden="true"></i>' . __( 'Go Pro', 'themesflat' ) . '</a></p></div>',
        ] );
        $this->end_controls_section();
        $this->start_controls_section( 'section_grid_settings', [
            'label' => __( 'Grid Settings', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_SETTINGS,
        ] );
        $this->add_control( 'column_layout', [
            'label'       => __( 'Column Layout', 'themesflat' ),
            'type'        => Controls_Manager::SELECT,
            'options'     => array(
            'auto'   => __( 'Auto', 'themesflat' ),
            'custom' => __( 'Custom', 'themesflat' ),
        ),
            'default'     => 'auto',
            'description' => __( 'Set column layout to be <strong>Auto</strong> to let the widget auto calculate number of columns based on minimum column size specified. The option <strong>Custom</strong> lets you explicitly control number of columns based on screen width.', 'themesflat' ),
        ] );
        $this->add_control( 'min_column_size', [
            'label'      => __( 'Minimum Column Size', 'themesflat' ),
            'type'       => Controls_Manager::SLIDER,
            'size_units' => [ 'px' ],
            'default'    => [
            'size' => 300,
        ],
            'range'      => [
            'px' => [
            'min' => 50,
            'max' => 500,
        ],
        ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-uber-grid-container.tfl-grid-auto-column-layout' => 'grid-template-columns: repeat(auto-fit, minmax({{SIZE}}{{UNIT}}, 1fr));',
        ],
            'condition'  => [
            'column_layout' => 'auto',
        ],
        ] );
        $this->add_responsive_control( 'per_line', [
            'label'              => __( 'Columns per row', 'themesflat' ),
            'type'               => Controls_Manager::SELECT,
            'default'            => '3',
            'tablet_default'     => '2',
            'mobile_default'     => '1',
            'options'            => [
            '1' => '1',
            '2' => '2',
            '3' => '3',
            '4' => '4',
            '5' => '5',
            '6' => '6',
        ],
            'frontend_available' => true,
            'condition'          => [
            'column_layout' => 'custom',
        ],
        ] );
        $this->add_control( 'column_gap', [
            'label'      => __( 'Column Gap', 'themesflat' ),
            'type'       => Controls_Manager::SLIDER,
            'size_units' => [ 'px' ],
            'default'    => [
            'size' => 30,
        ],
            'range'      => [
            'px' => [
            'min' => 0,
            'max' => 100,
        ],
        ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-uber-grid-container' => 'column-gap: {{SIZE}}{{UNIT}};',
        ],
        ] );
        $this->add_control( 'row_gap', [
            'label'      => __( 'Row Gap', 'themesflat' ),
            'type'       => Controls_Manager::SLIDER,
            'size_units' => [ 'px' ],
            'default'    => [
            'size' => 30,
        ],
            'range'      => [
            'px' => [
            'min' => 0,
            'max' => 100,
        ],
        ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-uber-grid-container' => 'row-gap: {{SIZE}}{{UNIT}};',
        ],
        ] );
        $this->end_controls_section();
        $this->start_controls_section( 'section_testimonials_thumbnail', [
            'label'      => __( 'Author Thumbnail', 'themesflat' ),
            'tab'        => Controls_Manager::TAB_STYLE,
            'show_label' => false,
        ] );
        $this->add_control( 'thumbnail_border_radius', [
            'label'      => __( 'Thumbnail Border Radius', 'themesflat' ),
            'type'       => Controls_Manager::DIMENSIONS,
            'size_units' => [ 'px', '%' ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-testimonials .tfl-testimonial-user .tfl-image-wrapper img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
        ] );
        $this->add_control( 'thumbnail_size', [
            'label'      => __( 'Thumbnail Size', 'themesflat' ),
            'type'       => Controls_Manager::SLIDER,
            'size_units' => [ '%', 'px' ],
            'range'      => [
            '%'  => [
            'min' => 10,
            'max' => 100,
        ],
            'px' => [
            'min' => 50,
            'max' => 156,
        ],
        ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-testimonials .tfl-testimonial-user .tfl-image-wrapper img' => 'max-width: {{SIZE}}{{UNIT}};',
        ],
        ] );
        $this->end_controls_section();
        $this->start_controls_section( 'section_testimonials_text', [
            'label' => __( 'Author Testimonial', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_responsive_control( 'text_padding', [
            'label'      => __( 'Text Padding', 'themesflat' ),
            'type'       => Controls_Manager::DIMENSIONS,
            'size_units' => [ 'px', 'em' ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-testimonials .tfl-testimonial-text' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
            'isLinked'   => false,
        ] );
        $this->add_control( 'text_color', [
            'label'     => __( 'Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-testimonials .tfl-testimonial-text' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_control( 'text_border_color', [
            'label'     => __( 'Border Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-testimonials .tfl-testimonial-text, {{WRAPPER}} .tfl-testimonials .tfl-testimonial-text:after' => 'border-color: {{VALUE}};',
        ],
        ] );
        $this->add_control( 'text_border_width', [
            'label'     => __( 'Border Width', 'themesflat' ),
            'type'      => Controls_Manager::SLIDER,
            'range'     => [
            'px' => [
            'min' => 1,
            'max' => 5,
        ],
        ],
            'selectors' => [
            '{{WRAPPER}} .tfl-testimonials .tfl-testimonial-text, {{WRAPPER}} .tfl-testimonials .tfl-testimonial-text:after' => 'border-width: {{SIZE}}{{UNIT}};',
        ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'text_typography',
            'selector' => '{{WRAPPER}} .tfl-testimonials .tfl-testimonial-text',
        ] );
        $this->end_controls_section();
        $this->start_controls_section( 'section_testimonials_author_name', [
            'label' => __( 'Author Name', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'title_tag', [
            'label'   => __( 'Title HTML Tag', 'themesflat' ),
            'type'    => Controls_Manager::SELECT,
            'options' => [
            'h1'  => __( 'H1', 'themesflat' ),
            'h2'  => __( 'H2', 'themesflat' ),
            'h3'  => __( 'H3', 'themesflat' ),
            'h4'  => __( 'H4', 'themesflat' ),
            'h5'  => __( 'H5', 'themesflat' ),
            'h6'  => __( 'H6', 'themesflat' ),
            'div' => __( 'div', 'themesflat' ),
        ],
            'default' => 'h4',
        ] );
        $this->add_control( 'title_color', [
            'label'     => __( 'Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-testimonials .tfl-testimonial-user .tfl-text .tfl-author-name' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'title_typography',
            'selector' => '{{WRAPPER}} .tfl-testimonials .tfl-testimonial-user .tfl-text .tfl-author-name',
        ] );
        $this->end_controls_section();
        $this->start_controls_section( 'section_testimonials_author_credentials', [
            'label' => __( 'Author Credentials', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'credential_color', [
            'label'     => __( 'Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-testimonials .tfl-testimonial-user .tfl-text' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'credential_typography',
            'selector' => '{{WRAPPER}} .tfl-testimonials .tfl-testimonial-user .tfl-text',
        ] );
        $this->end_controls_section();
    }
    
    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $settings = apply_filters( 'tfl_testimonials_' . $this->get_id() . '_settings', $settings );
        $args['settings'] = $settings;
        $args['widget_instance'] = $this;
        tfl_get_template_part( 'addons/testimonials/loop', $args );
    }
    
    protected function content_template()
    {
    }

}