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

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

    public function get_title()
    {
        return __('Related Product', '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 content tab

        /**
         * Header
         */
        $this->start_controls_section(
            'section_control_header',
            [
                'label' => __('Header', 'widgetkit-pro'),
            ]
        );
            $this->add_control(
                'product_to_show',
                [
                    'label'       => __( 'Product Count', 'widgetkit-pro' ),
                    'type' => Controls_Manager::SELECT,
                    'default' => '3',
                    'options' => [
                        '1'  => __( '1', 'widgetkit-pro' ),
                        '2'  => __( '2', 'widgetkit-pro' ),
                        '3'  => __( '3', 'widgetkit-pro' ),
                        '4'  => __( '4', 'widgetkit-pro' ),
                        '5'  => __( '5', 'widgetkit-pro' ),
                        '6'  => __( '6', 'widgetkit-pro' ),
                    ],
                ]
            );
            $this->add_control(
                'product_column',
                [
                    'label'       => __( 'Column', 'widgetkit-pro' ),
                    'type' => Controls_Manager::SELECT,
                    'default' => '3',
                    'options' => [
                        '1'  => __( '1', 'widgetkit-pro' ),
                        '2'  => __( '2', 'widgetkit-pro' ),
                        '3'  => __( '3', 'widgetkit-pro' ),
                        '4'  => __( '4', 'widgetkit-pro' ),
                        '5'  => __( '5', 'widgetkit-pro' ),
                        '6'  => __( '6', 'widgetkit-pro' ),
                    ],
                ]
            );
        $this->end_controls_section();
// #endregion        


// # region style tab

        $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-related-product h2',
            ]
        );
        $this->add_control(
            'header_color',
            [
                'label' => __( 'Color', 'widgetkit-pro' ),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .woo-single-product-related-product h2' => '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-related-product h2' => 'margin-bottom: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->end_controls_section();

    // #region header style
        /**
         * header style
         */
        $this->start_controls_section(
            'rp_title',
            [
                'label' => __( 'Title', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => __( 'Typography', 'widgetkit-pro' ),
                'name' => 'rp_title_typography',
                'selector' => '{{WRAPPER}} .woo-single-product-related-product .products .woocommerce-loop-product__title',
            ]
        );
        $this->add_control(
            'rp_title_color',
            [
                'label' => __( 'Color', 'widgetkit-pro' ),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .woo-single-product-related-product .products .woocommerce-loop-product__title' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'rp_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-related-product .products .woocommerce-loop-product__title' => 'margin-bottom: {{SIZE}}{{UNIT}};',
				],
            ]
        );
        
        $this->end_controls_section();
    // #endregion

    // #region header style
        /**
         * header style
         */
        $this->start_controls_section(
            'rp_price_header',
            [
                'label' => __( 'Price', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => __( 'Typography', 'widgetkit-pro' ),
                'name' => 'rp_price_typography',
                'selector' => '{{WRAPPER}} .woo-single-product-related-product .products .price',
            ]
        );
        $this->add_control(
            'rp_price_color',
            [
                'label' => __( 'Color', 'widgetkit-pro' ),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .woo-single-product-related-product .products .price' => 'color: {{VALUE}} ',
                ],
            ]
        );
        $this->add_control(
            'rp_price_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-related-product .products .price' => 'margin-bottom: {{SIZE}}{{UNIT}};',
				],
            ]
        );
        
        $this->end_controls_section();
    // #endregion

    // #region header style
        /**
         * header style
         */
        $this->start_controls_section(
            'rp_button',
            [
                'label' => __( 'Button', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => __( 'Typography', 'widgetkit-pro' ),
                'name' => 'rp_button_typography',
                'selector' => '{{WRAPPER}} .woo-single-product-related-product .products .button',
            ]
        );
        /**
         * tab start for title
         */
        $this->start_controls_tabs('rp_button_tabs');
            /**
             * Normal Tab
             */
            $this->start_controls_tab(
                'rp_button_normal',
                [
                    'label' => __( 'Normal', 'widgetkit-pro' ),
                ]
            );
            $this->add_control(
                'rp_button_color',
                [
                    'label' => __( 'Color', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-related-product .products .button' => 'color: {{VALUE}} ',
                    ],
                ]
            );
            $this->add_control(
                'rp_button_background',
                [
                    'label' => __( 'Background', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-related-product .products .button' => 'background: {{VALUE}} ',
                    ],
                ]
            );
            $this->end_controls_tab();
            /**
             * Hover style
             */
            $this->start_controls_tab(
                'rp_button_hover',
                [
                    'label' => __( 'Hover', 'widgetkit-pro' ),
                ]
            );
            $this->add_control(
                'rp_button_color_hover',
                [
                    'label' => __( 'Color', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-related-product .products .button:hover' => 'color: {{VALUE}} ',
                    ],
                ]
            );
            $this->add_control(
                'rp_button_background_hover',
                [
                    'label' => __( 'Background', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-related-product .products .button:hover' => 'background: {{VALUE}} ',
                    ],
                ]
            );
            $this->end_controls_tab();
        $this->end_controls_tabs();

        $this->add_responsive_control(
            'rp_button_padding',
            [
                'label'         => __('Padding', 'widgetkit-pro'),
                'type'          => Controls_Manager::DIMENSIONS,
                'size_units'    => ['px','%'],
                'separator'     => 'before',
                'selectors'     => [
                    '{{WRAPPER}} .woo-single-product-related-product .products .button' => '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(
            'rp_layout',
            [
                'label' => __( 'Layout', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_responsive_control(
            'rp-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-related-product .products li' => 'align-items: {{VALUE}};',
                    '{{WRAPPER}} .woo-single-product-related-product .products li a.woocommerce-loop-product__link' => 'align-items: {{VALUE}};',
                ],
            ]
        );
        
        $this->end_controls_section();
    // #endregion

    }


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

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

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

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