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

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

    public function get_title()
    {
        return __('Cart Button', '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' => __( 'Button', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => __( 'Typography', 'widgetkit-pro' ),
                'name' => 'section_title_typography',
                'selector' => '{{WRAPPER}} .woo-single-product-cart-button .cart-button-wrapper button[type="submit"]',
            ]
        );
        /**
         * tab start for title
         */
        $this->start_controls_tabs('primary_section_title_style_tabs');
            /**
             * Normal Tab
             */
            $this->start_controls_tab(
                'primary_section_title_style_normal',
                [
                    'label' => __( 'Normal', 'widgetkit-pro' ),
                ]
            );
            $this->add_control(
                'primary_content_title_color',
                [
                    'label' => __( 'Color', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-cart-button .cart-button-wrapper button[type="submit"]' => 'color: {{VALUE}} ',
                    ],
                ]
            );
            $this->add_control(
                'product_cart_background_color',
                [
                    'label' => __( 'Background', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-cart-button .cart-button-wrapper button[type="submit"]' => 'background-color: {{VALUE}} ',
                    ],
                ]
            );
            $this->end_controls_tab();
            /**
             * Hover style
             */
            $this->start_controls_tab(
                'primary_section_title_style_hover',
                [
                    'label' => __( 'Hover', 'widgetkit-pro' ),
                ]
            );
            $this->add_control(
                'primary_content_title_color_hover',
                [
                    'label' => __( 'Color', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-cart-button .cart-button-wrapper button[type="submit"]:hover' => 'color: {{VALUE}} ',
                    ],
                ]
            );
            $this->add_control(
                'product_cart_background_color_hover',
                [
                    'label' => __( 'Background', 'widgetkit-pro' ),
                    'type' => Controls_Manager::COLOR,
                    'default' => '',
                    'selectors' => [
                        '{{WRAPPER}} .woo-single-product-cart-button .cart-button-wrapper button[type="submit"]:hover' => 'background-color: {{VALUE}} ',
                    ],
                ]
            );
            $this->end_controls_tab();
        $this->end_controls_tabs();

        $this->add_responsive_control(
            'product_cart_padding',
            [
                'label'         => __('Padding', 'widgetkit-pro'),
                'type'          => Controls_Manager::DIMENSIONS,
                'size_units'    => ['px','%'],
                'separator'     => 'before',
                'selectors'     => [
                    '{{WRAPPER}} .woo-single-product-cart-button .cart-button-wrapper button[type="submit"]' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        
        $this->end_controls_section();
    // #endregion

    // #region input style
        /**
         * Input
         */
        $this->start_controls_section(
            'section_style_input',
            [
                'label' => __( 'Input', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        $this->add_responsive_control(
            'product_cart_input_padding',
            [
                'label'         => __('Padding', 'widgetkit-pro'),
                'type'          => Controls_Manager::DIMENSIONS,
                'size_units'    => ['px','%'],
                'separator'     => 'before',
                'selectors'     => [
                    '{{WRAPPER}} .woo-single-product-cart-button .cart-button-wrapper input[type="number"]' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        
        $this->end_controls_section();
    // #endregion

    // #region input style
        /**
         * Input
         */
        $this->start_controls_section(
            'section_style_variation',
            [
                'label' => __( 'Variation', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        /**
         * variation Picker
         */
        $this->add_control(
            'section_variation_picker',
            [
            'label' => __( 'Picker', 'widgetkit-pro' ),
            'type' => Controls_Manager::HEADING,
            'separator' => 'before',
            ]
        );
        $this->add_control(
            'product_cart_variation_picker_color',
            [
                'label' => __( 'Label Color', 'widgetkit-pro' ),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .woo-single-product-cart-button .type-variable table.variations td.label' => 'color: {{VALUE}} ',
                    '{{WRAPPER}} .woo-single-product-cart-button .type-variable table.variations a.reset_variations' => 'color: {{VALUE}} ',
                ],
            ]
        );
        /**
         * variation Content
         */
        $this->add_control(
            'section_variation_content',
            [
            'label' => __( 'Content', 'widgetkit-pro' ),
            'type' => Controls_Manager::HEADING,
            'separator' => 'before',
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => __( 'Typography', 'widgetkit-pro' ),
                'name' => 'section_variation_content_typography',
                'selector' => '{{WRAPPER}} .woo-single-product-cart-button .type-variable .woocommerce-variation-description',
            ]
        );
        $this->add_control(
            'product_cart_variation_content_color',
            [
                'label' => __( 'Color', 'widgetkit-pro' ),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .woo-single-product-cart-button .type-variable .woocommerce-variation-description' => 'color: {{VALUE}} ',
                ],
            ]
        );
        /**
         * variation price
         */
        $this->add_control(
            'section_variation_price',
            [
            'label' => __( 'Price', 'widgetkit-pro' ),
            'type' => Controls_Manager::HEADING,
            'separator' => 'before',
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => __( 'Typography', 'widgetkit-pro' ),
                'name' => 'section_variation_price_typography',
                'selector' => '{{WRAPPER}} .woo-single-product-cart-button .type-variable .woocommerce-variation-price',
            ]
        );
        $this->add_control(
            'product_cart_variation_price_color',
            [
                'label' => __( 'Color', 'widgetkit-pro' ),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .woo-single-product-cart-button .type-variable .woocommerce-variation-price' => '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(
            '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}} .column .cat-content' => '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-cart-button<?php echo $this->get_id(); ?>" class="woo-single-product-cart-button woo-single-product-cart-button-<?php echo $this->get_id() ?>">

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

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