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

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

    public function get_title()
    {
        return __('Categories', '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_label',
            [
                'label' => __('Label', 'widgetkit-pro'),
            ]
        );
            $this->add_control(
                'category_layout_label',
                [
                    'label'       => __( 'Text', 'widgetkit-pro' ),
                    'type'        => Controls_Manager::TEXT,
                    'default'     => __( 'Categories', 'widgetkit-pro' ),
                    'placeholder' => __( 'Categories', 'widgetkit-pro' ),
                ]
            );
        $this->end_controls_section();

        /**
         * Layout 
         */
        $this->start_controls_section(
            'section_control_layout',
            [
                'label' => __('Layout', 'widgetkit-pro'),
            ]
        );
            $this->add_control(
                'cat_layout',
                [
                    'label'       => __( 'Style', 'widgetkit-pro' ),
                    'type' => Controls_Manager::SELECT,
                    'default' => 'grid',
                    'options' => [
                        'grid'  => __( 'Grid', 'widgetkit-pro' ),
                        'list'  => __( 'List', 'widgetkit-pro' ),
                    ],
                ]
            );
            $this->add_control(
                'category_column',
                [
                    'label'   => __( 'Column', 'widgetkit-pro' ),
                    'type'    => Controls_Manager::NUMBER,
                    'default' => 3,
                    'min'     => 1,
                    'max'     => 8,
                    'step'    => 1,
                    'condition' => [
                        'cat_layout' => 'grid'
                    ]
                ]
            );
            $this->add_responsive_control(
                'layout_grid_gap',
                [
                    'label'   => esc_html__( 'Grid Gap', 'widgetkit-pro' ),
                    'type'    => Controls_Manager::SLIDER,
                    'default' => [
                        'size' =>10,
                    ],
                    'range'  => [
                        'px' => [
                            'min' => 0,
                            'max' => 50,
                        ],
                    ],
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-categories .single-product-category-wrapper .category-grid' => 'grid-gap: {{SIZE}}{{UNIT}};',
                    ],
                    'condition' => [
                        'cat_layout' => 'grid'
                    ]
                ]
            );
            $this->add_control(
                'show_category_count',
                [
                    'label' => __( 'Product Count', 'widgetkit-pro' ),
                    'type' => Controls_Manager::SWITCHER,
                    'default' => 'yes',
                    'label_on' => __( 'Yes', 'widgetkit-pro' ),
                    'label_off' => __( 'No', 'widgetkit-pro' ),
                    'return_value' => 'yes',
                    'condition' => [
                        'cat_layout' => 'grid'
                    ]
                ]
            );
            $this->add_responsive_control(
                'content_align',
                [
                    'label' => __( 'Alignment', 'widgetkit-pro' ),
                    'type' => Controls_Manager::CHOOSE,
                    'default' => 'center',
                    '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-categories .single-product-category-wrapper .cat-info-wrapper' => 'text-align: {{VALUE}};',
                    ],
                    'condition' => [
                        'cat_layout' => 'grid'
                    ]
                ]
            );
        
        $this->end_controls_section();

        

// #endregion        


// # region style tab

    // #region header style
        /**
         * header style
         */
        $this->start_controls_section(
            'section_style_label',
            [
                'label' => __( 'Label', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => __( 'Typography', 'widgetkit-pro' ),
                'name' => 'label_typography',
                'selector' => '{{WRAPPER}} .woo-single-product-categories .single-product-category-wrapper span.cat-label',
            ]
        );
        $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-categories .single-product-category-wrapper span.cat-label' => 'margin-bottom: {{SIZE}}{{UNIT}};',
                ],
                'condition' => [
                    'cat_layout' => 'grid'
                ]
            ]
        );
        
        $this->end_controls_section();
    // #endregion

    
    // #region image
        /**
         * image control
         */
        $this->start_controls_section(
            'section_style_image',
            [
                'label' => __( 'Image', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
                'condition' => [
                    'cat_layout' => 'grid'
                ]
            ]
        );
            $this->add_control(
                'cat_thumb_width',
                [
                    'label' => __( 'Width', 'widgetkit-pro' ),
                    'type' => Controls_Manager::SLIDER,
                    'default' => [
                        'size' => 100,
                    ],
                    'range' => [
                        'px' => [
                            'min' => 0,
                            'max' => 200,
                            'step' => 1,
                        ],
                    ],
                    'size_units' => [ 'px' ],
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-categories .single-product-category-wrapper .cat-thumb-image img' => 'width: {{SIZE}}{{UNIT}};',
                    ],
                ]
            );
            $this->add_control(
                'cat_thumb_height',
                [
                    'label' => __( 'Height', 'widgetkit-pro' ),
                    'type' => Controls_Manager::SLIDER,
                    'default' => [
                        'size' => 100,
                    ],
                    'range' => [
                        'px' => [
                            'min' => 0,
                            'max' => 200,
                            'step' => 1,
                        ],
                    ],
                    'size_units' => [ 'px' ],
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-categories .single-product-category-wrapper .cat-thumb-image img' => 'height: {{SIZE}}{{UNIT}};',
                    ],
                ]
            );
            $this->add_control(
                'cat_thumb_style',
                [
                    'label'       => __( 'Image Style', 'widgetkit-pro' ),
                    'type' => Controls_Manager::SELECT,
                    'default' => 'cover',
                    'options' => [
                        'cover'  => __( 'Cover', 'widgetkit-pro' ),
                        'contain'  => __( 'Contain', 'widgetkit-pro' ),
                        'fill'  => __( 'Fill', 'widgetkit-pro' ),
                        'scale-down'  => __( 'Scale Down', 'widgetkit-pro' ),
                        'none'  => __( 'None', 'widgetkit-pro' ),
                        'unset'  => __( 'Unset', 'widgetkit-pro' ),
                    ],
                    'condition' => [
                        'cat_layout' => 'grid'
                    ]
                ]
            );
            $this->add_group_control(
                Group_Control_Border::get_type(), 
                [
                'name'          => 'image-border',
                'selector'      => '{{WRAPPER}} .woo-single-product-categories .single-product-category-wrapper .cat-thumb-image',
                ]
            );

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

    // #region category style
        /**
         * Layout
         */
        $this->start_controls_section(
            'section_style_category',
            [
                'label' => __( 'Category', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
            $this->add_group_control(
                Group_Control_Typography::get_type(),
                [
                    'label' => __( 'Typography', 'widgetkit-pro' ),
                    'name' => 'product_category_name_typography',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-categories .single-product-category-wrapper .cat-info-wrapper ',
                    ]
                ]
            );
            /**
             * tab start for title
             */
            $this->start_controls_tabs('cat_link_color_tabs');
                /**
                 * Normal Tab
                 */
                $this->start_controls_tab(
                    'cat_link_style_normal',
                    [
                        'label' => __( 'Normal', 'widgetkit-pro' ),
                    ]
                );
                $this->add_control(
                    'cat_link_color',
                    [
                        'label' => __( 'Color', 'widgetkit-pro' ),
                        'type' => Controls_Manager::COLOR,
                        'default' => '#3d3d3d',
                        'selectors' => [
                            '{{WRAPPER}} .woo-single-product-categories .single-product-category-wrapper .cat-info-wrapper a' => 'color: {{VALUE}} ',
                        ],
                    ]
                );
                $this->end_controls_tab();
                /**
                 * Hover style
                 */
                $this->start_controls_tab(
                    'cat_link_style_hover',
                    [
                        'label' => __( 'Hover', 'widgetkit-pro' ),
                    ]
                );
                $this->add_control(
                    'cat_link_color_hover',
                    [
                        'label' => __( 'Color', 'widgetkit-pro' ),
                        'type' => Controls_Manager::COLOR,
                        'default' => '#7c7000',
                        'selectors' => [
                            '{{WRAPPER}} .woo-single-product-categories .single-product-category-wrapper .cat-info-wrapper a:hover' => 'color: {{VALUE}} ',
                        ],
                    ]
                );
                $this->end_controls_tab();
            $this->end_controls_tabs();
            
            $this->add_responsive_control(
                'cat_link_padding',
                [
                    'label'         => __('Padding', 'widgetkit-pro'),
                    'type'          => Controls_Manager::DIMENSIONS,
                    'size_units'    => ['px','%'],
                    'separator'     => 'before',
                    'selectors'     => [
                        '{{WRAPPER}} .woo-single-product-categories .single-product-category-wrapper .cat-info-wrapper' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                    ],
                    'default' => [
                        'top' => '5',
                        'right' => '5',
                        'bottom' => '5',
                        'left' => '5',
                        'unit' => 'px',
                        'isLinked' => false,
                    ],
                ]
            );
            $this->add_control(
                'cat_link_background_color',
                [
                    'label' => __( 'Background', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-categories .single-product-category-wrapper .cat-info-wrapper' => 'background-color: {{VALUE}} ',
                    ],
                ]
            );
        $this->end_controls_section();
    // #endregion

    }


    protected function render()
    {
        $settings = $this->get_settings();
        $cat_layout = widgetkit_pro_array_get($settings, 'cat_layout');
        $category_column = widgetkit_pro_array_get($settings, 'category_column');
        $show_category_count = widgetkit_pro_array_get($settings, 'show_category_count');
        $cat_thumb_style = widgetkit_pro_array_get($settings, 'cat_thumb_style');
        $category_layout_label = widgetkit_pro_array_get($settings, 'category_layout_label');
        // $cat_layout = widgetkit_pro_array_get($settings, 'cat_layout');
        ?>

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

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

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