<?php
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Scheme_Color;
use Elementor\Group_Control_Typography;
Use Elementor\Core\Schemes\Typography;
use Elementor\Group_Control_Border;
use Elementor\Utils;
use Elementor\Group_Control_Text_Shadow;

if (!defined('ABSPATH')) exit; // Exit if accessed directly

class Widgetkit_Pro_Woo_Single_Product_Review extends Widget_Base
{

    public function get_name()
    {
        return 'widgetkit-pro-woo-single-product-review';
    }

    public function get_title()
    {
        return __('Review', 'widgetkit-pro');
    }

    public function get_icon()
    {
        return 'eicon-woocommerce';
    }

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

    /**
	 * A list of style that the widgets is depended in
	 **/
	public function get_style_depends() {
        return [
            'widgetkit_bs',
            'widgetkit_pro_default',
        ];
    }
	/**
	 * A list of scripts that the widgets is depended in
	 **/
	public function get_script_depends() {
		return [ 
			// 'layout',
		 ];
	}

    protected function register_controls()
    {     

// # region style tab

    // #region header style
        /**
         * header style
         */
        $this->start_controls_section(
            'section_style_header',
            [
                'label' => __( 'Header', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => __( 'Typography', 'widgetkit-pro' ),
                'name' => 'section_header_typography',
                'selector' => '{{WRAPPER}} .woo-single-product-review .woocommerce-Reviews-title',
            ]
        );
        $this->add_control(
            'header_color',
            [
                'label' => __( 'Color', 'widgetkit-pro' ),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .woo-single-product-review .woocommerce-Reviews-title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'header_bottom_spacing',
            [
                'label' => __( 'Bottom Spacing', 'widgetkit-pro' ),
                'type' => Controls_Manager::SLIDER,
                'default' => [
                    'size' => 35,
                ],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 100,
                        'step' => 1,
                    ],
                ],
                'size_units' => [ 'px' ],
                'selectors' => [
					'{{WRAPPER}} .woo-single-product-review .woocommerce-Reviews-title' => 'margin-bottom: {{SIZE}}{{UNIT}};',
				],
            ]
        );
        
        $this->end_controls_section();
    // #endregion

        // #region primary column style
        /**
         * Label
         */
        $this->start_controls_section(
            'reviews_style',
            [
                'label' => __( 'Reviews', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
            /**
             * star
             */
            $this->add_control(
                'star_section',
                [
                'label' => __( 'Star', 'widgetkit-pro' ),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
                ]
            );
            $this->add_control(
                'star_color',
                [
                    'label' => __( 'Color', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-review .commentlist .star-rating' => 'color: {{VALUE}} ',
                        '{{WRAPPER}} .woo-single-product-review .woocommerce-tabs #reviews p.stars a' => 'color: {{VALUE}} ',
                    ],
                ]
            );
            /**
             * reviewer
             */
            $this->add_control(
                'reviewer_section',
                [
                'label' => __( 'Reviewer', 'widgetkit-pro' ),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
                ]
            );
            $this->add_group_control(
                Group_Control_Typography::get_type(),
                [
                    'label' => __( 'Typography', 'widgetkit-pro' ),
                    'name' => 'review_author_typography',
                    'selector' =>'{{WRAPPER}} .woo-single-product-review .commentlist .meta .woocommerce-review__author, {{WRAPPER}} .woo-single-product-review .commentlist .meta .woocommerce-review__dash',
                    
                ]
            );
            $this->add_control(
                'review_author_color',
                [
                    'label' => __( 'Color', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '#3d3d3d',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-review .commentlist .meta .woocommerce-review__author' => 'color: {{VALUE}} ',
                        '{{WRAPPER}} .woo-single-product-review .commentlist .meta .woocommerce-review__dash' => 'color: {{VALUE}} ',
                    ],
                ]
            );
            /**
             * Date
             */
            $this->add_control(
                'date_section',
                [
                'label' => __( 'Date', 'widgetkit-pro' ),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
                ]
            );
            $this->add_group_control(
                Group_Control_Typography::get_type(),
                [
                    'label' => __( 'Typography', 'widgetkit-pro' ),
                    'name' => 'date_typography',
                    'selector' => '{{WRAPPER}} .woo-single-product-review .commentlist .woocommerce-review__published-date',
                ]
            );
            $this->add_control(
                'date_color',
                [
                    'label' => __( 'Color', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '#3d3d3d',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-review .commentlist .woocommerce-review__published-date' => 'color: {{VALUE}} ',
                    ],
                ]
            );
            /**
             * Content
             */
            $this->add_control(
                'content_section',
                [
                'label' => __( 'Content', 'widgetkit-pro' ),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
                ]
            );
            $this->add_group_control(
                Group_Control_Typography::get_type(),
                [
                    'label' => __( 'Typography', 'widgetkit-pro' ),
                    'name' => 'content_typography',
                    'selector' => '{{WRAPPER}} .woo-single-product-review .commentlist .description',
                ]
            );
            $this->add_control(
                'content_color',
                [
                    'label' => __( 'Color', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '#3d3d3d',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-review .commentlist .description' => 'color: {{VALUE}} ',
                    ],
                ]
            );
            /**
             * thumbnail
             */
            $this->add_control(
                'thumbnail_section',
                [
                'label' => __( 'Thumbnail', 'widgetkit-pro' ),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
                ]
            );
            $this->add_group_control(
                Group_Control_Border::get_type(), 
                [
                'name'          => 'thumbnail-border',
                'selector'      => '{{WRAPPER}} .woo-single-product-review .commentlist img',
                ]
            );
            $this->add_control(
                'thumbnail_radius',
                [
                    'label' => __( 'Radius', 'widgetkit-pro' ),
                    'type' => Controls_Manager::SLIDER,
                    'default' => [
                        'size' => 0,
                    ],
                    'range' => [
                        'px' => [
                            'min' => 0,
                            'max' => 100,
                            'step' => 1,
                        ],
                    ],
                    'size_units' => [ 'px' ],
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-review .commentlist img' => 'border-radius: {{SIZE}}{{UNIT}};',
                    ],
                ]
            );
            

        $this->end_controls_section();
    // #endregion

    // #region Form 
        /**
         * review form
         */
        $this->start_controls_section(
            'review_form_style',
            [
                'label' => __( 'Form', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
            $this->add_control(
                'review_title',
                [
                'label' => __( 'Title', 'widgetkit-pro' ),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
                ]
            );
            $this->add_group_control(
                Group_Control_Typography::get_type(),
                [
                    'label' => __( 'Typography', 'widgetkit-pro' ),
                    'name' => 'review_title_typography',
                    'selector' => '{{WRAPPER}} .woo-single-product-review .comment-reply-title',
                ]
            );
            $this->add_control(
                'review_title_color',
                [
                    'label' => __( 'Color', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '#3d3d3d',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-review .comment-reply-title' => 'color: {{VALUE}} ',
                    ],
                ]
            );
            $this->add_control(
                'review_title_bottom_spacing',
                [
                    'label' => __( 'Bottom Spacing', 'widgetkit-pro' ),
                    'type' => Controls_Manager::SLIDER,
                    'default' => [
                        'size' => 35,
                    ],
                    'range' => [
                        'px' => [
                            'min' => 0,
                            'max' => 100,
                            'step' => 1,
                        ],
                    ],
                    'size_units' => [ 'px' ],
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-review .comment-reply-title' => 'margin-bottom: {{SIZE}}{{UNIT}};',
                    ],
                ]
            );
            /**
             * form label
             */
            $this->add_control(
                'review_form_label',
                [
                'label' => __( 'Label', 'widgetkit-pro' ),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
                ]
            );
            $this->add_group_control(
                Group_Control_Typography::get_type(),
                [
                    'label' => __( 'Typography', 'widgetkit-pro' ),
                    'name' => 'review_form_label_typography',
                    'selector' => '{{WRAPPER}} .woo-single-product-review .comment-form label',
                ]
            );
            $this->add_control(
                'review_form_label_color',
                [
                    'label' => __( 'Color', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '#3d3d3d',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-review .comment-form label' => 'color: {{VALUE}} ',
                    ],
                ]
            );
            $this->add_control(
                'review_form_label_bottom_spacing',
                [
                    'label' => __( 'Bottom Spacing', 'widgetkit-pro' ),
                    'type' => Controls_Manager::SLIDER,
                    'default' => [
                        'size' => 35,
                    ],
                    'range' => [
                        'px' => [
                            'min' => 0,
                            'max' => 100,
                            'step' => 1,
                        ],
                    ],
                    'size_units' => [ 'px' ],
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-review  .comment-form label' => 'margin-bottom: {{SIZE}}{{UNIT}};',
                        '{{WRAPPER}} .woo-single-product-review  .comment-form .comment-form-rating label' => 'margin-bottom: {{SIZE}}{{UNIT}}; !important',
                    ],
                ]
            );
            /**
             * button
             */
            $this->add_control(
                'review_form_button',
                [
                'label' => __( 'Button', 'widgetkit-pro' ),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
                ]
            );
            $this->add_group_control(
                Group_Control_Typography::get_type(),
                [
                    'label' => __( 'Typography', 'widgetkit-pro' ),
                    'name' => 'review_form_button_typography',
                    'selector' => '{{WRAPPER}} .woo-single-product-review .comment-form input[type="submit"]',
                ]
            );
            /**
             * tab start for title
             */
            $this->start_controls_tabs('review_form_button_tabs');
                /**
                 * Normal Tab
                 */
                $this->start_controls_tab(
                    'review_form_button_normal',
                    [
                        'label' => __( 'Normal', 'widgetkit-pro' ),
                    ]
                );
                $this->add_control(
                    'review_form_button_color',
                    [
                        'label' => __( 'Color', 'widgetkit-pro' ),
                        'type' => Controls_Manager::COLOR,
                        'default' => '',
                        'selectors' => [
                            '{{WRAPPER}}  .woo-single-product-review .comment-form input[type="submit"]' => 'color: {{VALUE}} ',
                        ],
                    ]
                );
                $this->add_control(
                    'review_form_button_background',
                    [
                        'label' => __( 'Background', 'widgetkit-pro' ),
                        'type' => Controls_Manager::COLOR,
                        'default' => '',
                        'selectors' => [
                            '{{WRAPPER}}  .woo-single-product-review .comment-form input[type="submit"]' => 'background: {{VALUE}} ',
                        ],
                    ]
                );
                $this->end_controls_tab();
                /**
                 * Hover style
                 */
                $this->start_controls_tab(
                    'review_form_button_hover',
                    [
                        'label' => __( 'Hover', 'widgetkit-pro' ),
                    ]
                );
                $this->add_control(
                    'review_form_button_color_hover',
                    [
                        'label' => __( 'Color', 'widgetkit-pro' ),
                        'type' => Controls_Manager::COLOR,
                        'default' => '',
                        'selectors' => [
                            '{{WRAPPER}}  .woo-single-product-review .comment-form input[type="submit"]:hover' => 'color: {{VALUE}} ',
                        ],
                    ]
                );
                $this->add_control(
                    'review_form_button_background_hover',
                    [
                        'label' => __( 'Background', 'widgetkit-pro' ),
                        'type' => Controls_Manager::COLOR,
                        'default' => '',
                        'selectors' => [
                            '{{WRAPPER}}  .woo-single-product-review .comment-form input[type="submit"]:hover' => 'background: {{VALUE}} ',
                        ],
                    ]
                );
                $this->end_controls_tab();
            $this->end_controls_tabs();

            $this->add_responsive_control(
                'review_form_button_padding',
                [
                    'label'         => __('Padding', 'widgetkit-pro'),
                    'type'          => Controls_Manager::DIMENSIONS,
                    'size_units'    => ['px','%'],
                    'separator'     => 'before',
                    'selectors'     => [
                        '{{WRAPPER}} .woo-single-product-review .comment-form input[type="submit"]' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                    ],
                    // 'default' => [
                    //     'top' => '15',
                    //     'right' => '15',
                    //     'bottom' => '15',
                    //     'left' => '15',
                    //     'unit' => 'px',
                    //     'isLinked' => false,
                    // ],
                ]
            );

        $this->end_controls_section();
    // #endregion



    
    // #region layout style
        /**
         * Layout
         */
        $this->start_controls_section(
            'section_style_layout',
            [
                'label' => __( 'Layout', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_responsive_control(
            'content-align',
            [
                'label' => __( 'Alignment', 'widgetkit-pro' ),
                'type' => Controls_Manager::CHOOSE,
                'default' => 'left',
                'options' => [
                    'left'    => [
                        'title' => __( 'Left', 'widgetkit-pro' ),
                        'icon' => 'fa fa-align-left',
                    ],
                    'center' => [
                        'title' => __( 'Center', 'widgetkit-pro' ),
                        'icon' => 'fa fa-align-center',
                    ],
                    'right' => [
                        'title' => __( 'Right', 'widgetkit-pro' ),
                        'icon' => 'fa fa-align-right',
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .woo-single-product-review .woocommerce-Reviews-title' => 'text-align: {{VALUE}};',
                ],
            ]
        );
        
        $this->end_controls_section();
    // #endregion

    }


    protected function render()
    {
        $settings = $this->get_settings();
        $cat_query_type = widgetkit_pro_array_get($settings, 'cat_query_type');
        ?>

        <div id="woo-single-product-review<?php echo $this->get_id(); ?>" class="woo-single-product-review woo-single-product-review-<?php echo $this->get_id() ?>">

            <?php 
            include( plugin_dir_path( __FILE__ ) . '../layout/woo/single-product/review.php'); 
            // if($cat_query_type === 'specific_cat'){
            // }else{
            //     include( plugin_dir_path( __FILE__ ) . '../layout/woo/category/all-category.php'); 
            // }
            ?>
        </div>
        <script>
            jQuery(function($){
                if(!$('body').hasClass('wkpro-woo-single-product-review')){
                    $('body').addClass('wkpro-woo-single-product-review');
                }
            });
        </script>

    <?php
    }
    protected function _content_template()
    {
    }
}
