<?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_Rating extends Widget_Base
{

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

    public function get_title()
    {
        return __('Rating', '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_rating',
            [
                'label' => __( 'Rating', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
            $this->add_control(
                'rating_star_section',
                [
                'label' => __( 'Star ', 'widgetkit-pro' ),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
                ]
            );
            $this->add_control(
                'rating_star_color',
                [
                    'label' => __( 'Color', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '#3d3d3d',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-rating .woocommerce-product-rating .star-rating' => 'color: {{VALUE}} ',
                    ],
                ]
            );
            $this->add_responsive_control(
                'rating_star_font_size',
                [
                    'label'   => esc_html__( 'Font Size', 'widgetkit-for-elementor' ),
                    'type'    => Controls_Manager::SLIDER,
                    // 'default' => [
                    //     'size' =>20,
                    // ],
                    'range'  => [
                        'px' => [
                            'min' => 0,
                            'max' => 200,
                        ],
                    ],
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-rating .woocommerce-product-rating .star-rating' => 'font-size: {{SIZE}}{{UNIT}};',
                    ],
                ]
            );
            
            $this->add_control(
                'rating_text_section',
                [
                'label' => __( 'Text ', 'widgetkit-pro' ),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
                ]
            );
            $this->add_group_control(
                Group_Control_Typography::get_type(),
                [
                    'label' => __( 'Typography', 'widgetkit-pro' ),
                    'name' => 'rating_text_typography',
                    'selector' => '{{WRAPPER}} .woo-single-product-rating .woocommerce-product-rating .woocommerce-review-link',
                ]
            );
            $this->add_control(
                'rating_text_color',
                [
                    'label' => __( 'Color', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '#3d3d3d',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-rating .woocommerce-product-rating .woocommerce-review-link' => 'color: {{VALUE}} ',
                    ],
                ]
            );
        
        
        $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(
            'rating-align',
            [
                'label' => __( 'Alignment', 'widgetkit-pro' ),
                'type' => Controls_Manager::CHOOSE,
                'default' => 'flex-start',
                'options' => [
                    'flex-start'    => [
                        'title' => __( 'Left', 'widgetkit-pro' ),
                        'icon' => 'fa fa-align-left',
                    ],
                    'center' => [
                        'title' => __( 'Center', 'widgetkit-pro' ),
                        'icon' => 'fa fa-align-center',
                    ],
                    'flex-end' => [
                        'title' => __( 'Right', 'widgetkit-pro' ),
                        'icon' => 'fa fa-align-right',
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .woo-single-product-rating .woocommerce-product-rating' => 'justify-content: {{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-rating<?php echo $this->get_id(); ?>" class="woo-single-product-rating woo-single-product-rating-<?php echo $this->get_id() ?>">

            <?php 
            include( plugin_dir_path( __FILE__ ) . '../layout/woo/single-product/rating.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-rating')){
                    $('body').addClass('wkpro-woo-single-product-rating');
                }
            });
        </script>

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