<?php
if (!defined('ABSPATH')) exit; // Exit if accessed directly
use Elementor\Widget_Base;
use Elementor\Utils;
use Elementor\Icons_Manager;
use Elementor\Controls_Manager;
use Elementor\Control_Media;
use \Elementor\Group_Control_Box_Shadow;
use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Text_Stroke;
use Elementor\Group_Control_Typography;
use \Elementor\Group_Control_Image_Size;
use \Elementor\Group_Control_Background;
use \Elementor\Group_Control_Text_Shadow;

class Rswpthemes_Awt_Book_Reviews_Slider extends \Elementor\Widget_Base {

    public function get_name() {
        return 'rswpthemes_awt_book_reviews_slider';
    }

    public function get_title() {
        return __('Awt Book Reviews Slider', 'author-website-templates');
    }

    public function get_icon() {
        return 'dashicons dashicons-testimonial';
    }

    public function get_categories() {
        return ['rswpthemes_awt_widgets'];
    }

    public function get_style_depends(){
        return ['book-reviews-slider', 'slick'];
    }

    public function get_script_depends(){
        return ['rswpbs-review-slider-script', 'slick'];
    }

    protected function register_controls() {
        $this->start_controls_section(
            'content_section',
            [
                'label' => __('Content', 'author-website-templates'),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        // Section Heading
        $this->add_control(
            'section_heading',
            [
                'label' => __('Section Heading', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => __('Words From Our Happy Readers.', 'author-website-templates'),
            ]
        );

        // Section Subheading
        $this->add_control(
            'section_sub_heading',
            [
                'label' => __('Section Sub Heading', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => __('Testimonial', 'author-website-templates'),
            ]
        );

        // Reviews Per Page
        $this->add_control(
            'review_per_page',
            [
                'label' => __('Reviews Per Page', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::NUMBER,
                'default' => 8,
            ]
        );

        // Review Layout
        $this->add_control(
            'review_layout',
            [
                'label' => __('Review Layout', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'options' => [
                    'slider' => __('Slider', 'author-website-templates'),
                    'grid' => __('Grid', 'author-website-templates'),
                ],
                'default' => 'slider',
            ]
        );

        // Select Book
        $this->add_control(
            'select_book',
            [
                'label' => __('Select Book', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => '',
            ]
        );

        // Show Slider Navigation
        $this->add_control(
            'show_slider_navigation',
            [
                'label' => __('Show Slider Navigation', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'author-website-templates'),
                'label_off' => __('Hide', 'author-website-templates'),
                'default' => 'true',
                'return_value' => 'true',
            ]
        );

        // Show Section Title
        $this->add_control(
            'show_section_title',
            [
                'label' => __('Show Section Title', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'author-website-templates'),
                'label_off' => __('Hide', 'author-website-templates'),
                'default' => 'true',
                'return_value' => 'true',
            ]
        );

        // Show Quote
        $this->add_control(
            'show_quote',
            [
                'label' => __('Show Quote', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'author-website-templates'),
                'label_off' => __('Hide', 'author-website-templates'),
                'default' => 'true',
                'return_value' => 'true',
            ]
        );

        // Show Ratings
        $this->add_control(
            'show_ratings',
            [
                'label' => __('Show Ratings', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'author-website-templates'),
                'label_off' => __('Hide', 'author-website-templates'),
                'default' => 'true',
                'return_value' => 'true',
            ]
        );

        // Show Reviewer
        $this->add_control(
            'show_reviewer',
            [
                'label' => __('Show Reviewer', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => __('Show', 'author-website-templates'),
                'label_off' => __('Hide', 'author-website-templates'),
                'default' => 'true',
                'return_value' => 'true',
            ]
        );

        // Screen size controls
        $this->add_control(
            'large_screen',
            [
                'label' => __('Large Screen Columns', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::NUMBER,
                'default' => 3,
                'classes' => 'pro-locked-control',
            ]
        );

        $this->add_control(
            'medium_screen',
            [
                'label' => __('Medium Screen Columns', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::NUMBER,
                'default' => 2,
                'classes' => 'pro-locked-control',
            ]
        );

        $this->add_control(
            'small_screen',
            [
                'label' => __('Small Screen Columns', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::NUMBER,
                'default' => 1,
                'classes' => 'pro-locked-control',
            ]
        );

        $this->add_control(
            'layout_style',
            [
                'label' => __('Layout Style', 'author-website-templates'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'options' => [
                    'classic' => __('Classic', 'author-website-templates'),
                    'modern' => __('Modern', 'author-website-templates'),
                ],
                'default' => 'classic',
                'classes' => 'pro-locked-control',
            ]
        );

        $this->end_controls_section();
        $this->start_controls_section(
            'awt_brs_section_subtitle_style',
            [
                'label' => __( 'Section Sub Title Style', 'author-website-templates' ),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
       $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'awt_brs_section_subtitle_typography',
                'selector' => '{{WRAPPER}} .customer-reveiw-section-title h4',
            ]
        );
       $this->add_control(
            'awt_brs_section_subtitle_color',
            [
                'label' => __( 'Color', 'author-website-templates' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .customer-reveiw-section-title h4' => 'color: {{VALUE}}',
                ],
            ]
        );
       $this->end_controls_section();
       $this->start_controls_section(
            'awt_brs_section_title_style',
            [
                'label' => __( 'Section Title Style', 'author-website-templates' ),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
       $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'awt_brs_section_title_typography',
                'selector' => '{{WRAPPER}} .customer-reveiw-section-title h2',
            ]
        );
       $this->add_control(
            'awt_brs_section_title_color',
            [
                'label' => __( 'Color', 'author-website-templates' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .customer-reveiw-section-title h2' => 'color: {{VALUE}}',
                ],
            ]
        );
       $this->end_controls_section();

        $this->start_controls_section(
            'awt_brs_wrapper',
            [
                'label' => __( 'Review Box Style', 'author-website-templates' ),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->start_controls_tabs(
            'awt_brs_container_style_tabs'
        );
        $this->start_controls_tab(
            'awt_brs_container_normal_tab',
            [
                'label' => __( 'Normal', 'author-website-templates' ),
            ]
        );

        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'awt_brs_container_background',
                'separator' => 'before',
                'label' => __( 'Box Background', 'author-website-templates' ),
                'types' => [ 'classic', 'gradient' ],
                'selector' => '{{WRAPPER}} .rswpbs-customer-review-wrapper .testimonial__item-inner, {{WRAPPER}} .rswpthemes-book-loop-content-wrapper',
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'box_shadow',
                'separator' => 'before',
                'label' => __( 'Box Shadow', 'author-website-templates' ),
                'selector' => '{{WRAPPER}} .rswpbs-customer-review-wrapper .testimonial__item-inner',
            ]
        );
        $this->add_responsive_control(
            'awt_brs_container_padding',
            [
                'label' => __( 'Content Padding', 'author-website-templates' ),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', 'em', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .rswpthemes-book-loop-content-wrapper' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
                'separator' => 'before',
            ]
        );
        $this->add_responsive_control(
            'awt_brs_item_box_padding',
            [
                'label' => __( 'Item Padding', 'author-website-templates' ),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', 'em', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .rswpbs-customer-review-wrapper .testimonial__item-inner' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
                'separator' => 'before',
            ]
        );
        $this->add_responsive_control(
            'awt_brs_container_margin',
            [
                'label' => __( 'Item Margin', 'author-website-templates' ),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', 'em', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .rswpbs-customer-review-wrapper .testimonial__item-inner' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
                'separator' => 'before',
            ]
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'awt_brs_container_border',
                'selector' => '{{WRAPPER}} .rswpbs-customer-review-wrapper .testimonial__item-inner',
                'separator' => 'before',
            ]
        );

        $this->end_controls_tab();
        $this->start_controls_tab(
            'awt_brs_container_hover_tab',
            [
                'label' => __( 'Hover', 'author-website-templates' ),
            ]
        );
        $this->add_group_control(
            Group_Control_Background::get_type(),
            [
                'name' => 'awt_brs_container_hover_background',
                'label' => __( 'Box Background', 'author-website-templates' ),
                'types' => [ 'classic', 'gradient' ],
                'selector' => '{{WRAPPER}} .rswpbs-customer-review-wrapper .testimonial__item-inner:hover',
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'awt_brs_container_hover_shadow',
                'label' => __( 'Box Shadow', 'author-website-templates' ),
                'selector' => '{{WRAPPER}} .rswpbs-customer-review-wrapper .testimonial__item-inner:hover',
            ]
        );
        $this->end_controls_tab();
        $this->end_controls_tabs();
        $this->end_controls_section();
        $this->start_controls_section(
            'awt_brs_qoute_style',
            [
                'label' => __( 'Qoute Style', 'author-website-templates' ),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
       $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'awt_brs_qoute_typography',
                'selector' => '{{WRAPPER}} .ratings-and-quote-wrapper .quote',
            ]
        );
       $this->add_control(
            'awt_brs_qoute_color',
            [
                'label' => __( 'Color', 'author-website-templates' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .ratings-and-quote-wrapper .quote' => 'color: {{VALUE}}',
                ],
            ]
        );
       $this->end_controls_section();
        $this->start_controls_section(
            'awt_brs_stars_style',
            [
                'label' => __( 'Stars Style', 'author-website-templates' ),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
       $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'awt_brs_stars_typography',
                'selector' => '{{WRAPPER}} .testimonial__item-inner .client-rating span',
            ]
        );
       $this->add_control(
            'awt_brs_stars_color',
            [
                'label' => __( 'Color', 'author-website-templates' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial__item-inner .client-rating span' => 'color: {{VALUE}}',
                ],
            ]
        );
       $this->end_controls_section();
        $this->start_controls_section(
            'awt_brs_name_style',
            [
                'label' => __( 'Name Style', 'author-website-templates' ),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
       $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'awt_brs_name_typography',
                'selector' => '{{WRAPPER}} .testimonial__item-inner h4.client-name',
            ]
        );
       $this->add_control(
            'awt_brs_name_color',
            [
                'label' => __( 'Color', 'author-website-templates' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .testimonial__item-inner h4.client-name' => 'color: {{VALUE}}',
                ],
            ]
        );
       $this->end_controls_section();
        $this->start_controls_section(
            'awt_brs_comment_style',
            [
                'label' => __( 'Comment Style', 'author-website-templates' ),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        );
       $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'awt_brs_comment_typography',
                'selector' => '{{WRAPPER}} .review-short-content, {{WRAPPER}} .review-full-content',
            ]
        );
       $this->add_control(
            'awt_brs_comment_color',
            [
                'label' => __( 'Color', 'author-website-templates' ),
                'separator' => 'before',
                'type' => \Elementor\Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .review-short-content, {{WRAPPER}} .review-full-content' => 'color: {{VALUE}}',
                ],
            ]
        );
       $this->end_controls_section();

        /**
         * Navigation Style
         */
        $this->start_controls_section(
            'awt_brs_nav_style_section',
            [
                'label' => __( 'Navigation Style', 'author-website-templates' ),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->start_controls_tabs(
            'awt_brs_nav_style_tab'
        );
        $this->start_controls_tab(
            'awt_brs_nav_normal_tab',
            [
                'label' =>  __( 'Normal', 'author-website-templates' ),
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'awt_brs_nav_typography',
                'selector' => '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div',
            ]
        );
        $this->add_control(
            'awt_brs_nav_color',
            [
                'label' => __( 'Button Color', 'author-website-templates' ),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->add_control(
            'awt_brs_nav_bg_color',
            [
                'label' => __( 'Button Background', 'author-website-templates' ),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div' => 'background: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'awt_brs_nav_border',
                'selector' => '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div',
                'separator' => 'before',
            ]
        );

        $this->add_control(
            'awt_brs_nav_border_radius',
            [
                'label' => __( 'Border Radius', 'author-website-templates' ),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'awt_brs_nav_box_shadow',
                'separator' => 'before',
                'label' => __( 'Box Shadow', 'author-website-templates' ),
                'selector' => '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div',
            ]
        );
        $this->end_controls_tab();
        $this->start_controls_tab(
            'awt_brs_nav_hover_tab',
            [
                'label' =>  __( 'Hover', 'author-website-templates' ),
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'awt_brs_nav_hover_typography',
                'selector' => '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div:hover',
            ]
        );
        $this->add_control(
            'awt_brs_nav_hover_color',
            [
                'label' => __( 'Button Color', 'author-website-templates' ),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div:hover' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'awt_brs_nav_bg_hover_color',
            [
                'label' => __( 'Button Background', 'author-website-templates' ),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div:hover' => 'background: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'awt_brs_nav_hover_border',
                'selector' => '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div:hover',
                'separator' => 'before',
            ]
        );
        $this->add_control(
            'awt_brs_nav_border_hover_radius',
            [
                'label' => __( 'Border Radius', 'author-website-templates' ),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'awt_brs_nav_box_shadow_hover',
                'separator' => 'before',
                'label' => __( 'Box Shadow', 'author-website-templates' ),
                'selector' => '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div:hover',
            ]
        );
        $this->end_controls_tab();
        $this->end_controls_tabs();
        $this->add_responsive_control(
            'awt_brs_nav_padding',
            [
                'label' => __( 'Padding', 'author-website-templates' ),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', 'em', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
                'separator' => 'before',
            ]
        );
        $this->add_responsive_control(
            'awt_brs_nav_margin',
            [
                'label' => __( 'Margin', 'author-website-templates' ),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', 'em', '%' ],
                'selectors' => [
                    '{{WRAPPER}} .rswpbs_customer-review-slider-pagination>div' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
                'separator' => 'before',
            ]
        );
        $this->end_controls_section();
    }
    protected function render() {
        $settings = $this->get_settings_for_display();

        $review_per_page = $settings['review_per_page'];
        $review_layout = $settings['review_layout'];
        $section_sub_heading = $settings['section_sub_heading'];
        $section_heading = $settings['section_heading'];
        $select_book = $settings['select_book'];
        $show_slider_navigation = $settings['show_slider_navigation'] === 'true' ? 'true' : 'false';
        $show_section_title = $settings['show_section_title'] === 'true' ? 'true' : 'false';
        $show_quote = $settings['show_quote'] === 'true' ? 'true' : 'false';
        $show_ratings = $settings['show_ratings'] === 'true' ? 'true' : 'false';
        $show_reviewer = $settings['show_reviewer'] === 'true' ? 'true' : 'false';
        $large_screen = $settings['large_screen'];
        $medium_screen = $settings['medium_screen'];
        $small_screen = $settings['small_screen'];
        $layout_style = $settings['layout_style'];

        echo '<div class="extra-addon-testimonial-section">';
        echo do_shortcode("[rswpbs_reviews container=\"container\" review_per_page=\"$review_per_page\" review_layout=\"$review_layout\" section_sub_heading=\"$section_sub_heading\" section_heading=\"$section_heading\" select_book=\"$select_book\" show_slider_navigation=\"$show_slider_navigation\" show_section_title=\"$show_section_title\" show_quote=\"$show_quote\" show_ratings=\"$show_ratings\" show_reviewer=\"$show_reviewer\" large_screen=\"$large_screen\" medium_screen=\"$medium_screen\" small_screen=\"$small_screen\" layout_style=\"$layout_style\"]");
        echo '</div>';
    }
}
