<?php

namespace Elementor;

include get_template_directory() . '/elementor/' . 'contracts.php';

if (!defined('ABSPATH')) exit;

class ProductTabs3 extends Widget_Base
{

    public function get_name()
    {
        return 'banta_product_tabs_3';
    }

    public function get_title()
    {
        return __('Product Tabs 3', TEXT_DOMAIN);
    }

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

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

    public function get_keywords()
    {
        return ['card', 'box', 'list', 'products', 'tabs', 'nav', 'categories'];
    }

    protected function _register_controls()
    {
        $this->register_content_tab_tabs_controls();
        $this->register_content_tab_products_controls();
        $this->register_content_tab_items();
        $this->register_content_tab_query_controls();

        $this->register_style_tabs_controls();
        $this->register_style_tab_card_controls();
        $this->register_style_tab_image_controls();
        $this->register_style_tab_title_controls();
        $this->register_style_tab_price_controls();
        $this->register_style_tab_rating_controls();
        $this->register_style_tab_cart_button_controls();
        $this->register_style_tab_view_button_controls();
    }


    // tabs
    protected function register_content_tab_tabs_controls()
    {
        $this->start_controls_section(
            'section_tabs',
            [
                'label' => esc_html__('tabs', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'tabs_align',
            [
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'label' => esc_html__( 'Alignment', TEXT_DOMAIN ),
                'options' => [
                    'justify-content-start' => [
                        'title' => esc_html__( 'right', TEXT_DOMAIN ),
                        'icon' => 'eicon-text-align-right',
                    ],
                    'justify-content-center' => [
                        'title' => esc_html__( 'center', TEXT_DOMAIN ),
                        'icon' => 'eicon-text-align-center',
                    ],
                    'justify-content-end' => [
                        'title' => esc_html__( 'left', TEXT_DOMAIN ),
                        'icon' => 'eicon-text-align-left',
                    ],
                ],
                'default' => 'card-content-center',
            ]
        );

        $repeater = new Repeater();

        $categories = get_terms( [
            'taxonomy' => 'product_cat',
            'hide_empty' => false,
        ] );

        $category_options = [];
        foreach ( $categories as $category ) {
            $category_options[$category->term_id . '|' . $category->name] = $category->name;
        }

        $repeater->add_control(
            'icon',
            [
                'label' => __( 'Icon', TEXT_DOMAIN ),
                'type' => \Elementor\Controls_Manager::ICONS,
            ]
        );

        $repeater->add_control(
            'category_id',
            [
                'label' => __( 'Select Category', TEXT_DOMAIN),
                'type' => \Elementor\Controls_Manager::SELECT2,
                'label_block' => true,
                'options' => $category_options,
                'multiple' => false,
                'default' => '',
            ]
        );

        $this->add_control(
            'selected_categories',
            [
                'label' => esc_html__('Items', TEXT_DOMAIN),
                'type' => \Elementor\Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
                // Extract just the name part from the encoded value
                'title_field' => '<# 
            var parts = category_id ? category_id.split("|") : ["", "No Category"]; 
            print(parts[1]); 
        #>',
                'frontend_available' => true,
            ]
        );


        $this->end_controls_section();
    }



    // products content
    protected function register_content_tab_products_controls()
    {
        $this->start_controls_section(
            'section_content',
            [
                'label' => esc_html__('Content', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        // rating
        $this->add_control(
            'show_title',
            [
                'label' => esc_html__('Show title', TEXT_DOMAIN),
                'type' => Controls_Manager::SWITCHER,
                'default' => 'yes',
                'separator' => 'before'
            ]
        );

        $this->add_control(
            'title_tag',
            [
                'type' => Controls_Manager::SELECT,
                'label' => esc_html__('Title html tag', TEXT_DOMAIN),
                'options' => HTML_TAGS,
                'default' => 'h3',
                'condition' => [
                    'show_title' => 'yes'
                ]
            ]
        );


        $this->add_control(
            'image_size',
            [
                'type' => Controls_Manager::SELECT,
                'label' => esc_html__('image size', TEXT_DOMAIN),
                'options' => THUMB_SIZES,
                'default' => 'medium',
            ]
        );

        $this->add_control(
            'content_align',
            [
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'label' => esc_html__('Alignment', TEXT_DOMAIN),
                'options' => [
                    'card-content-left' => [
                        'title' => esc_html__('left', TEXT_DOMAIN),
                        'icon' => 'eicon-text-align-left',
                    ],
                    'card-content-center' => [
                        'title' => esc_html__('center', TEXT_DOMAIN),
                        'icon' => 'eicon-text-align-center',
                    ],
                    'card-content-right' => [
                        'title' => esc_html__('right', TEXT_DOMAIN),
                        'icon' => 'eicon-text-align-right',
                    ],
                ],
                'default' => 'card-content-right',
            ]
        );

        // quick look
        $this->add_control(
            'show_quick_view',
            [
                'label' => esc_html__('Show quick view button', TEXT_DOMAIN),
                'type' => Controls_Manager::SWITCHER,
                'default' => 'yes',
                'separator' => 'before',
            ]
        );

        // rating
        $this->add_control(
            'show_rating',
            [
                'label' => esc_html__('show rating', TEXT_DOMAIN),
                'type' => Controls_Manager::SWITCHER,
                'default' => 'no',
                'separator' => 'before'
            ]
        );

        $this->add_control(
            'free_text',
            [
                'label' => esc_html__('Edit Product Free Label', TEXT_DOMAIN),
                'type' => Controls_Manager::TEXT,
                'placeholder' => __('Free', TEXT_DOMAIN),
                'default' => __('Free', TEXT_DOMAIN),
                'label_block' => true,
                'separator' => 'before'
            ]
        );

        $this->end_controls_section();
    }

    // items
    protected function register_content_tab_items()
    {
        $this->start_controls_section(
            'items_section',
            [
                'label' => esc_html__('Items', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'col',
            [
                'type' => Controls_Manager::SELECT,
                'label' => esc_html__('desktop', TEXT_DOMAIN),
                'options' => BS_ROWS,
                'default' => '3',
            ]
        );
        $this->add_control(
            'col_tablet',
            [
                'type' => Controls_Manager::SELECT,
                'label' => esc_html__('tablet', TEXT_DOMAIN),
                'options' => BS_ROWS,
                'default' => '4',
            ]
        );
        $this->add_control(
            'col_mobile',
            [
                'type' => Controls_Manager::SELECT,
                'label' => esc_html__('mobile', TEXT_DOMAIN),
                'options' => BS_ROWS,
                'default' => '12'
            ]
        );

        $this->end_controls_section();

    }

    // query
    protected function register_content_tab_query_controls()
    {
        $this->start_controls_section(
            'section_query',
            [
                'label' => esc_html__('query', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
            'exclude_products',
            [
                'label' => esc_html__('exclude products', TEXT_DOMAIN),
                'type' => Controls_Manager::TEXT,
                'placeholder' => 'product_id',
                'label_block' => true,
                'description' => __('Write the product ID here, if you want to remove multiple products, use a comma as separator. like 1, 2', TEXT_DOMAIN),
            ]
        );
        $this->add_control(
            'posts_per_page',
            [
                'label' => esc_html__('number of products', TEXT_DOMAIN),
                'type' => Controls_Manager::NUMBER,
                'default' => 8,
            ]
        );
        $this->add_control(
            'show_product_type',
            [
                'label' => esc_html__('products type', TEXT_DOMAIN),
                'type' => Controls_Manager::SELECT,
                'default' => 'total_sales',
                'options' => [
                    'all' => esc_html__('any', TEXT_DOMAIN),
                    'onsale' => esc_html__('onsale', TEXT_DOMAIN),
                    'featured' => esc_html__('featured', TEXT_DOMAIN),
                ],
            ]
        );
        $this->add_control(
            'hide_free',
            [
                'label' => esc_html__('hide free', TEXT_DOMAIN),
                'type' => Controls_Manager::SWITCHER,
            ]
        );
        $this->add_control(
            'hide_out_stock',
            [
                'label' => esc_html__('hide out of stock', TEXT_DOMAIN),
                'type' => Controls_Manager::SWITCHER,
            ]
        );
        $this->add_control(
            'orderby',
            [
                'label' => esc_html__('sort by', TEXT_DOMAIN),
                'type' => Controls_Manager::SELECT,
                'default' => 'date',
                'options' => [
                    'date' => esc_html__('date', TEXT_DOMAIN),
                    'price' => esc_html__('price', TEXT_DOMAIN),
                    'sales' => esc_html__('sales', TEXT_DOMAIN),
                    'rand' => esc_html__('random', TEXT_DOMAIN),
                ],
            ]
        );
        $this->add_control(
            'order',
            [
                'label' => esc_html__('order', TEXT_DOMAIN),
                'type' => Controls_Manager::SELECT,
                'default' => 'DESC',
                'options' => [
                    'DESC' => esc_html__('Descending', TEXT_DOMAIN),
                    'ASC' => esc_html__('Ascending', TEXT_DOMAIN),
                ],
            ]
        );

        $taxonomies = get_object_taxonomies('product', 'objects');
        unset($taxonomies['post_translations'], $taxonomies['post_format'], $taxonomies['product_cat']);
        foreach ($taxonomies as $taxonomy => $object) {
            $categories = get_terms(array(
                'taxonomy' => $object->name,
                'hide_empty' => 0,
            ));
            $cat_array = array();
            foreach ($categories as $cat_id => $cat_name) {
                $cat_array[$cat_name->term_id] = $cat_name->name;
            }
            @$this->add_control(
                $object->name,
                [
                    'label' => $object->label,
                    'type' => Controls_Manager::SELECT2,
                    'label_block' => true,
                    'multiple' => true,
                    'options' => $cat_array,
                ]
            );
        }

        $this->end_controls_section();
    }


    // style tabs
    protected function register_style_tabs_controls()
    {
        $this->start_controls_section(
            'section_tabs_style',
            [
                'label' => esc_html__('tabs', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_responsive_control(
            'tab_direction',
            [
                'type' => \Elementor\Controls_Manager::CHOOSE,
                'label' => esc_html__( 'Tab direction', TEXT_DOMAIN ),
                'options' => [
                    'flex-row' => [
                        'title' => esc_html__( 'horizontal', TEXT_DOMAIN ),
                        'icon' => 'eicon-h-align-stretch',
                    ],
                    'flex-column' => [
                        'title' => esc_html__( 'vertical', TEXT_DOMAIN ),
                        'icon' => 'eicon-v-align-middle',
                    ],

                ],
                'default' => 'card-content-center',
            ]
        );

        $this->add_responsive_control(
            'tabs_tab_width',
            [
                'label' => __('width', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px','%'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 500,
                    ],
                    '%' => [
                        'min' => 0,
                        'max' => 100,
                    ]
                ],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item' => 'width: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );
        $this->add_responsive_control(
            'tabs_tab_height',
            [
                'label' => __('height', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px','%'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 500,
                    ],
                    '%' => [
                        'min' => 0,
                        'max' => 100,
                    ]
                ],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item' => 'height: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_responsive_control(
            'tabs_head_margin',
            [
                'label' => __('bottom margin', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px','%'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 500,
                    ],
                    '%' => [
                        'min' => 0,
                        'max' => 100,
                    ]
                ],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-head' => 'margin-bottom: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

        // icon
        $this->add_control(
            'tabs_icon_heading',
            [
                'label' => esc_html__('Icon', TEXT_DOMAIN),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before'
            ]
        );
        $this->add_responsive_control(
            'tabs_icon_margin',
            [
                'label' => __('margin', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px','%'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 500,
                    ],
                    '%' => [
                        'min' => 0,
                        'max' => 100,
                    ]
                ],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item' => 'gap: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );
        $this->add_responsive_control(
            'tabs_icon_size',
            [
                'label' => __('Icon size', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item i' => 'font-size: {{SIZE}}{{UNIT}}!important;',
                    '{{WRAPPER}} .bcp-tabs-nav-item svg' => 'width: {{SIZE}}{{UNIT}}!important;height: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );




        $this->add_control(
            'tabs_nav_heading',
            [
                'label' => esc_html__('links', TEXT_DOMAIN),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before'
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'tabs_nav_typography',
                'label' => esc_html__('typography', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .bcp-tabs-nav-item ',
            ]
        );
        $this->add_responsive_control(
            'tabs_nav_margin',
            [
                'label' => esc_html__('margin', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item' => 'margin-left: {{SIZE}}{{UNIT}};',
                ],
            ]
        );

        $this->start_controls_tabs(
            'tabs_nav_style_tabs'
        );
        // normal tab
        $this->start_controls_tab(
            'tabs_nav_style_normal_tab',
            [
                'label' => esc_html__('normal', TEXT_DOMAIN),
            ]
        );
        $this->add_responsive_control(
            'tabs_nav_badge_height',
            [
                'label' => __('Badge height', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 40,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item:before' => 'height: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );
        $this->add_responsive_control(
            'tabs_nav_padding',
            [
                'label' => esc_html__('padding', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_responsive_control(
            'tabs_nav_radius',
            [
                'label' => __('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item:before,{{WRAPPER}} .bcp-tabs-nav-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'tabs_nav_color',
            [
                'label' => esc_html__('text color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'tabs_nav_bg',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'tabs_icon_color',
            [
                'label' => esc_html__('Icon color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item i' => 'color: {{VALUE}};',
                    '{{WRAPPER}} .bcp-tabs-nav-item svg' => 'stroke: {{VALUE}};',
                    '{{WRAPPER}} .bcp-tabs-nav-item svg path' => 'stroke: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'tabs_nav_border_type',
                'label' => esc_html__('border', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .bcp-tabs-nav-item',
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'tabs_nav_shadow',
                'selector' => '{{WRAPPER}} .bcp-tabs-nav-item',
            ]
        );
        $this->end_controls_tab();
        // hover tab
        $this->start_controls_tab(
            'tabs_nav_style_hover_tab',
            [
                'label' => esc_html__('hover', TEXT_DOMAIN),
            ]
        );
        $this->add_responsive_control(
            'tabs_nav_padding_hover',
            [
                'label' => esc_html__('padding', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item:hover' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_responsive_control(
            'tabs_nav_radius_hover',
            [
                'label' => __('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item:hover:before' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'tabs_nav_color_hover',
            [
                'label' => esc_html__('text color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item:hover' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'tabs_nav_bg_hover',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item:hover:before' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'tabs_icon_color_hover',
            [
                'label' => esc_html__('Icon color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item:hover i' => 'color: {{VALUE}}!important;',
                    '{{WRAPPER}} .bcp-tabs-nav-item:hover svg' => 'stroke: {{VALUE}} !important;',
                    '{{WRAPPER}} .bcp-tabs-nav-item:hover svg path' => 'stroke: {{VALUE}} !important;',
                ],
            ]
        );
        $this->add_control(
            'tabs_nav_badge_hover',
            [
                'label' => esc_html__('badge color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item:hover:before' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'tabs_nav_border_type_hover',
                'label' => esc_html__('border', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .bcp-tabs-nav-item:hover',
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'tabs_nav_shadow_hover',
                'selector' => '{{WRAPPER}} .bcp-tabs-nav-item:hover:before',
            ]
        );
        $this->end_controls_tab();
        // active tab
        $this->start_controls_tab(
            'tabs_nav_style_active_tab',
            [
                'label' => esc_html__('active', TEXT_DOMAIN),
            ]
        );
        $this->add_responsive_control(
            'tabs_nav_badge_height_active',
            [
                'label' => __('Badge height', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 40,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item.active:before' => 'height: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );
        $this->add_responsive_control(
            'tabs_nav_padding_active',
            [
                'label' => esc_html__('padding', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item.active' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_responsive_control(
            'tabs_nav_radius_active',
            [
                'label' => __('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item.active:before' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'tabs_nav_color_active',
            [
                'label' => esc_html__('text color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item.active' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'tabs_nav_bg_active',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item.active' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'tabs_icon_color_active',
            [
                'label' => esc_html__('Icon color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item.active i' => 'color: {{VALUE}}!important;',
                    '{{WRAPPER}} .bcp-tabs-nav-item.active svg' => 'stroke: {{VALUE}}!important;',
                    '{{WRAPPER}} .bcp-tabs-nav-item.active svg path' => 'stroke: {{VALUE}}!important;',
                ],
            ]
        );
        $this->add_control(
            'tabs_nav_badge_active',
            [
                'label' => esc_html__('badge color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .bcp-tabs-nav-item.active:before' => 'background-color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'tabs_nav_border_type_active',
                'label' => esc_html__('border', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .bcp-tabs-nav-item.active',
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'tabs_nav_shadow_active',
                'selector' => '{{WRAPPER}} .bcp-tabs-nav-item.active:before',
            ]
        );
        $this->end_controls_tab();
        $this->end_controls_tabs();

        $this->end_controls_section();
    }



    // style box
    protected function register_style_tab_card_controls()
    {
        $this->start_controls_section(
            'section_box_style',
            [
                'label' => esc_html__('Box', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_responsive_control(
            'box_margin',
            [
                'label' => __('margin', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'default' => [
                    'size' => 25,
                    'unit' => 'px',
                ],

                'selectors' => [
                    '{{WRAPPER}} .product-card' => 'margin-bottom: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_responsive_control(
            'box_padding',
            [
                'label' => esc_html__('padding', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .product-card' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->start_controls_tabs(
            'box_style_tabs', [
                'separator' => 'before'
            ]
        );

        // normal tab
        $this->start_controls_tab(
            'box_style_normal_tab',
            [
                'label' => esc_html__('normal', TEXT_DOMAIN),
            ]
        );

        $this->add_responsive_control(
            'box_radius',
            [
                'label' => __('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .product-card' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'box_color',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card' => 'background-color: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'box_border_type',
                'label' => esc_html__('border', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .product-card',
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'box_shadow',
                'selector' => '{{WRAPPER}} .product-card',
            ]
        );
        $this->end_controls_tab();

        // hover tab
        $this->start_controls_tab(
            'box_style_hover_tab',
            [
                'label' => esc_html__('hover', TEXT_DOMAIN),
            ]
        );
        $this->add_responsive_control(
            'box_radius_hover',
            [
                'label' => __('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', 'rem'],
                'selectors' => [
                    '{{WRAPPER}} .product-card:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_control(
            'box_color_hover',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card:hover' => 'background-color: {{VALUE}};',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'box_border_type_hover',
                'label' => esc_html__('border', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .product-card:hover',
            ]
        );
        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'box_shadow_hover',
                'selector' => '{{WRAPPER}} .product-card:hover',
            ]
        );
        $this->end_controls_tab();

        $this->end_controls_tabs();
        $this->end_controls_section();
    }

    // style image
    protected function register_style_tab_image_controls()
    {
        $this->start_controls_section(
            'section_image_style',
            [
                'label' => esc_html__('Image', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );


        $this->add_responsive_control(
            'image_padding',
            [
                'label' => esc_html__('margin', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', 'em', '%'],
                'selectors' => [
                    '{{WRAPPER}} .product-card-image' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );

        $this->add_responsive_control(
            'image_border_radius',
            [
                'label' => esc_html__('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .product-card-image img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_responsive_control(
            'image_margin',
            [
                'label' => __('margin', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .product-card-image img' => 'margin-bottom: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->end_controls_section();
    }

    // style title
    protected function register_style_tab_title_controls()
    {
        $this->start_controls_section(
            'section_title_style',
            [
                'label' => esc_html__('Title', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'title_typography',
                'label' => esc_html__('typography', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .product-card .title',
            ]
        );
        $this->add_responsive_control(
            'title_margin',
            [
                'label' => __('margin', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 100,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .product-card .title' => 'margin-bottom: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );
        $this->add_control(
            'title_transition',
            [
                'label' => __('transition', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['s', 'ms'],
                'range' => [
                    's' => [
                        'min' => 1,
                        'max' => 100,
                    ],
                    'ms' => [
                        'min' => 1,
                        'max' => 1000,
                    ],
                ],
                'default' => [
                    'unit' => 'ms',
                    'size' => 200
                ],
                'selectors' => [
                    '{{WRAPPER}} .product-card .title' => 'transition: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->start_controls_tabs(
            'title_style_tabs', [
                'separator' => 'before'
            ]
        );

        // normal tab
        $this->start_controls_tab(
            'title_style_normal_tab',
            [
                'label' => esc_html__('normal', TEXT_DOMAIN),
            ]
        );
        $this->add_control(
            'title_color',
            [
                'label' => esc_html__('color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card .title' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Text_Shadow::get_type(),
            [
                'name' => 'title_text_shadow',
                'selector' => '{{WRAPPER}} .product-card .title',
            ]
        );
        $this->end_controls_tab();

        // hover tab
        $this->start_controls_tab(
            'title_style_hover_tab',
            [
                'label' => esc_html__('hover', TEXT_DOMAIN),
            ]
        );
        $this->add_control(
            'title_color_hover',
            [
                'label' => esc_html__('color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card .title:hover' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Text_Shadow::get_type(),
            [
                'name' => 'title_text_shadow_hover',
                'selector' => '{{WRAPPER}} .product-card .title:hover',
            ]
        );
        $this->end_controls_tab();

        $this->end_controls_tabs();
        $this->end_controls_section();
    }

    // style price
    protected function register_style_tab_price_controls()
    {
        $this->start_controls_section(
            'section_price_style',
            [
                'label' => esc_html__('Price', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );

        // price
        $this->add_control(
            'price_heading',
            [
                'label' => esc_html__('price', TEXT_DOMAIN),
                'type' => Controls_Manager::HEADING,
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'price_typography',
                'label' => esc_html__('typography', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .product-card .current-price',
            ]
        );
        $this->add_control(
            'price_color',
            [
                'label' => esc_html__('color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card .current-price' => 'color: {{VALUE}}!important;',
                ],
            ]
        );


        // main price
        $this->add_control(
            'old_price_heading',
            [
                'label' => esc_html__('main price', TEXT_DOMAIN),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'old_price_typography',
                'label' => esc_html__('typography', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .product-card .old-price',
            ]
        );
        $this->add_control(
            'old_price_color',
            [
                'label' => esc_html__('color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card .old-price' => 'color: {{VALUE}}!important;',
                ],
            ]
        );

        // symbol
        $this->add_control(
            'tooman_heading',
            [
                'label' => esc_html__('price symbol', TEXT_DOMAIN),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'price_tooman_typography',
                'label' => esc_html__('typography', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .product-card .tooman',
            ]
        );
        $this->add_control(
            'price_tooman_color',
            [
                'label' => esc_html__('color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card .tooman' => 'color: {{VALUE}}!important;',
                ],
            ]
        );

        // percent
        $this->add_control(
            'percent_heading',
            [
                'label' => esc_html__('discount percent', TEXT_DOMAIN),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'percent_typography',
                'label' => esc_html__('typography', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .price-discount-percent',
            ]
        );
        $this->add_responsive_control(
            'percent_size',
            [
                'label' => __('size', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 1,
                        'max' => 200,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .price-discount-percent' => 'width: {{SIZE}}{{UNIT}}!important;height: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );
        $this->add_control(
            'percent_color',
            [
                'label' => esc_html__('color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .price-discount-percent' => 'color: {{VALUE}}!important;',
                ],
            ]
        );
        $this->add_control(
            'percent_bg_color',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .price-discount-percent' => 'background-color: {{VALUE}}!important;',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'percent_border_type',
                'label' => esc_html__('border', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .price-discount-percent',
            ]
        );


        $this->add_responsive_control(
            'percent_border_radius',
            [
                'label' => esc_html__('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .price-discount-percent' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
                ],
            ]
        );


        $this->end_controls_section();
    }

    // style rating
    protected function register_style_tab_rating_controls()
    {
        $this->start_controls_section(
            'section_rating_style',
            [
                'label' => esc_html__('Ratings', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_STYLE,
                'condition' => [
                    'show_rating' => 'yes',
                ],
            ]
        );
        $this->add_control(
            'rating_color',
            [
                'label' => esc_html__('Color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'default' => '#e7e7e7',
                'selectors' => [
                    '{{WRAPPER}} .product-card .star-rating:before' => 'color: {{VALUE}};',
                ]
            ]
        );
        $this->add_control(
            'active_rating_color',
            [
                'label' => esc_html__('Active Color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'default' => '#FFCC00',
                'selectors' => [
                    '{{WRAPPER}} .product-card .star-rating span::before' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_responsive_control(
            'rating_size',
            [
                'label' => __('size', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em'],
                'range' => [
                    'px' => [
                        'min' => 1,
                        'max' => 100,
                    ],
                    'em' => [
                        'min' => 1,
                        'max' => 10,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .product-card .star-rating' => 'font-size: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );
        $this->add_responsive_control(
            'rating_margin',
            [
                'label' => __('margin', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 200,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .product-card .star-rating' => 'margin-bottom: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );
        $this->end_controls_section();
    }

    // style cart button
    protected function register_style_tab_cart_button_controls()
    {
        $this->start_controls_section(
            'section_cart_button_style',
            [
                'label' => esc_html__('Cart Button', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );


        $this->add_responsive_control(
            'cart_button_icon_size',
            [
                'label' => __('Icon size', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 1,
                        'max' => 200,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-cart' => 'font-size: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );


        $this->start_controls_tabs(
            'cart_button_style_tabs', [
                'separator' => 'before'
            ]
        );

        // normal tab
        $this->start_controls_tab(
            'cart_button_style_normal_tab',
            [
                'label' => esc_html__('normal', TEXT_DOMAIN),
            ]
        );
        $this->add_control(
            'cart_button_icon_color',
            [
                'label' => esc_html__('Icon color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-cart' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'cart_button_bg',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-cart' => 'background-color: {{VALUE}}!important;',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'cart_button_border_type',
                'label' => esc_html__('border', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .product-card-3-cart',
            ]
        );
        $this->add_responsive_control(
            'cart_button_border_radius',
            [
                'label' => esc_html__('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-cart' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'cart_button_shadow',
                'selector' => '{{WRAPPER}} .product-card-3-cart',
            ]
        );
        $this->end_controls_tab();

        // hover tab
        $this->start_controls_tab(
            'cart_button_style_hover_tab',
            [
                'label' => esc_html__('hover', TEXT_DOMAIN),
            ]
        );
        $this->add_control(
            'cart_button_icon_color_hover',
            [
                'label' => esc_html__('Icon color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-cart:hover' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'cart_button_bg_hover',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-cart:hover' => 'background-color: {{VALUE}}!important;',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'cart_button_border_type_hover',
                'label' => esc_html__('border', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .product-card-3-cart:hover',
            ]
        );
        $this->add_responsive_control(
            'ocart_button_border_radius_hover',
            [
                'label' => esc_html__('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-cart:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'cart_button_shadow_hover',
                'selector' => '{{WRAPPER}} .product-card-3-cart:hover',
            ]
        );
        $this->end_controls_tab();
        $this->end_controls_tabs();


        $this->end_controls_section();
    }

    // style quick view button
    protected function register_style_tab_view_button_controls()
    {
        $this->start_controls_section(
            'section_view_button_style',
            [
                'label' => esc_html__('Quick View Button', TEXT_DOMAIN),
                'tab' => Controls_Manager::TAB_STYLE,
                'condition' => [
                    'show_quick_view' => 'yes'
                ]
            ]
        );


        $this->add_responsive_control(
            'view_button_icon_size',
            [
                'label' => __('Icon size', TEXT_DOMAIN),
                'type' => Controls_Manager::SLIDER,
                'size_units' => ['px', 'em', 'rem'],
                'range' => [
                    'px' => [
                        'min' => 1,
                        'max' => 200,
                    ],
                ],
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-view' => 'font-size: {{SIZE}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'name' => 'view_button_typography',
                'label' => esc_html__('typography', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .product-card-3-view .card-3-btn-title',
            ]
        );


        $this->start_controls_tabs(
            'view_button_style_tabs', [
                'separator' => 'before'
            ]
        );

        // normal tab
        $this->start_controls_tab(
            'view_button_style_normal_tab',
            [
                'label' => esc_html__('normal', TEXT_DOMAIN),
            ]
        );
        $this->add_control(
            'view_button_icon_color',
            [
                'label' => esc_html__('Icon color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-view' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'view_button_text_color',
            [
                'label' => esc_html__('Text color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-view .card-3-btn-title' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'view_button_bg',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-view' => 'background-color: {{VALUE}}!important;',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'view_button_border_type',
                'label' => esc_html__('border', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .product-card-3-view',
            ]
        );
        $this->add_responsive_control(
            'view_button_border_radius',
            [
                'label' => esc_html__('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-view' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'view_button_shadow',
                'selector' => '{{WRAPPER}} .product-card-3-view',
            ]
        );
        $this->end_controls_tab();

        // hover tab
        $this->start_controls_tab(
            'view_button_style_hover_tab',
            [
                'label' => esc_html__('hover', TEXT_DOMAIN),
            ]
        );
        $this->add_control(
            'view_button_icon_color_hover',
            [
                'label' => esc_html__('Icon color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-view:hover' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'view_button_text_color_hover',
            [
                'label' => esc_html__('Text color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-view:hover .card-3-btn-title' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_control(
            'view_button_bg_hover',
            [
                'label' => esc_html__('background color', TEXT_DOMAIN),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-view:hover' => 'background-color: {{VALUE}}!important;',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [
                'name' => 'view_button_border_type_hover',
                'label' => esc_html__('border', TEXT_DOMAIN),
                'selector' => '{{WRAPPER}} .product-card-3-view:hover',
            ]
        );
        $this->add_responsive_control(
            'view_button_border_radius_hover',
            [
                'label' => esc_html__('border radius', TEXT_DOMAIN),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => ['px', '%'],
                'selectors' => [
                    '{{WRAPPER}} .product-card-3-view:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}!important;',
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Box_Shadow::get_type(),
            [
                'name' => 'view_button_shadow_hover',
                'selector' => '{{WRAPPER}} .product-card-3-view:hover',
            ]
        );
        $this->end_controls_tab();
        $this->end_controls_tabs();


        $this->end_controls_section();
    }


    public function calculatePricePercentage($product)
    {
        if ($product->is_type('variable')) {
            $percentages = array();

            // Get all variation prices
            $prices = $product->get_variation_prices();

            // Loop through variation prices
            foreach ($prices['price'] as $key => $price) {
                // Only on sale variations
                if ($prices['regular_price'][$key] !== $price) {
                    // Calculate and set in the array the percentage for each variation on sale
                    $percentages[] = round(100 - (floatval($prices['sale_price'][$key]) / floatval($prices['regular_price'][$key]) * 100));
                }
            }
            // We keep the highest value
            if (count($percentages) < 1) {
                $percentage = '0%';
            }else{
                $percentage = max($percentages) . '%';
            }

        } elseif ($product->is_type('grouped')) {
            $percentages = array();

            // Get all variation prices
            $children_ids = $product->get_children();

            // Loop through variation prices
            foreach ($children_ids as $child_id) {
                $child_product = wc_get_product($child_id);

                $regular_price = (float)$child_product->get_regular_price();
                $sale_price = (float)$child_product->get_sale_price();

                if ($sale_price != 0 || !empty($sale_price)) {
                    // Calculate and set in the array the percentage for each child on sale
                    $percentages[] = round(100 - ($sale_price / $regular_price * 100));
                }
            }
            // We keep the highest value
            if (count($percentages) < 1) {
                $percentage = '0%';
            }else{
                $percentage = max($percentages) . '%';
            }

        } else {
            $regular_price = (float)$product->get_regular_price();
            $sale_price = (float)$product->get_sale_price();

            if ($sale_price != 0 || !empty($sale_price)) {
                $percentage = round(100 - ($sale_price / $regular_price * 100)) . '%';
            } else {
                $percentage = 0;
            }
        }

        return $percentage;
    }

    public function bcp_wc_get_rating_html($rating, $count = 0)
    {
        $html = '';
        $label = sprintf(__('Rated %s out of 5', 'woocommerce'), $rating);
        $html = '<div class="woocommerce"><div class="star-rating" role="img" aria-label="' . esc_attr($label) . '">' . wc_get_star_rating_html($rating, $count) . '</div></div>';
        return apply_filters('woocommerce_product_get_rating_html', $html, $rating, $count);
    }


    protected function is_product_in_stock($product)
    {
        if (!$product) {
            return false;
        }

        $product_type = $product->get_type();

        switch ($product_type) {
            case 'simple':
            case 'external':
                return $product->is_in_stock();

            case 'variable':
                $variations = $product->get_available_variations();
                if (empty($variations)) {
                    return false;
                }
                foreach ($variations as $variation_data) {
                    $variation = wc_get_product($variation_data['variation_id']);
                    if ($variation && $variation->is_in_stock()) {
                        return true;
                    }
                }
                return false;

            case 'grouped':
                $children = $product->get_children();
                if (empty($children)) {
                    return false;
                }
                foreach ($children as $child_id) {
                    $child_product = wc_get_product($child_id);

                    if ($child_product && is_product_in_stock($child_product)) {
                        return true;
                    }
                }
                return false;

            default:
                // برای سایر انواع محصولات
                return $product->is_in_stock();
        }
    }


    public function render_price($product,$freePriceText){
        if ($this->is_product_in_stock($product)){
            if( $product->is_type('variable')){
                $prices = $product->get_variation_prices();
                if (!empty($prices['regular_price'])) {
                    $regular_price = (float) min($prices['regular_price']);
                } else {
                    $regular_price = 0;
                }

                if (!empty($prices['sale_price'])) {
                    $sale_price = (float) min($prices['sale_price']);
                } else {
                    $sale_price = 0;
                }

            }elseif( $product->is_type('grouped') ){
                $children_ids = $product->get_children();
                $child_product = wc_get_product($children_ids[0]);
                $regular_price = (float) $child_product->get_regular_price();
                $sale_price    = (float) $child_product->get_sale_price();

            }else{
                $regular_price = (float) $product->get_regular_price();
                $sale_price    = (float) $product->get_sale_price();
            }

            echo "<div class='product-price-container'>";

            $percentage = $this->calculatePricePercentage($product);
            if (intval(str_replace('%','',$percentage)) > 0 && !$product->is_type('variable')):
                echo "<div class='price-discount-percent'>".$percentage."</div>";
            endif;

            echo "<div class='product-price'>";
            if ($regular_price == 0){
                if (!empty($freePriceText)) {
                    echo '<span class="current-price">' . $freePriceText . '</span>';
                }
            }else{
                if ($regular_price == $sale_price){
                    echo "<div class='d-flex flex-column'><span class='current-price'>".number_format($regular_price)."</span><span class='tooman'>".get_woocommerce_currency_symbol()."</span></div>";
                }else{
                    if($sale_price == 0 ||  empty($sale_price) ){
                        echo "<div class='d-flex flex-column'><span class='current-price'>".number_format($regular_price)."</span><span class='tooman'>".get_woocommerce_currency_symbol()."</span></div>";

                    }else{
                        echo '<div class="current-price">'.number_format($sale_price).'</div>';
                        echo "<div class='d-flex'><span class='old-price'>".number_format($regular_price)."</span><span class='tooman ms-2'>".get_woocommerce_currency_symbol()."</span></div>";

                    }
                }
            }
            echo "</div></div>";
        }else{
            echo "<div class='product-price-container'><div class='out-of-stock-text'>".__('out of stock',TEXT_DOMAIN)."</div></div>";
        }
    }

    public function get_attribute_json($product)
    {

        $attributes = $product->get_attributes();

        if (!$attributes) {
            return;
        }

        $display_result = '';

        $attrCount = count($attributes);

        foreach ($attributes as $attribute) {

            if ($attribute->get_variation()) {
                continue;
            }

            $name = $attribute->get_name();

            if ($attribute->is_taxonomy()) {

                $terms = wp_get_post_terms($product->get_id(), $name, 'all');

                $tax = $terms[0]->taxonomy;

                $object_taxonomy = get_taxonomy($tax);

                if (isset ($object_taxonomy->labels->singular_name)) {

                    $tax_label = $object_taxonomy->labels->singular_name;

                } elseif (isset($object_taxonomy->label)) {

                    $tax_label = $object_taxonomy->label;

                    if (0 === strpos($tax_label, 'Product ')) {

                        $tax_label = substr($tax_label, 8);

                    }

                }

                $display_result .= '<li>' . $tax_label . ': ';

                $tax_terms = array();

                foreach ($terms as $term) {

                    $single_term = esc_html($term->name);

                    array_push($tax_terms, $single_term);

                }

                $display_result .= implode(', ', $tax_terms) . '</li>';


            } else {

                $display_result .= '<li>' . $name . ': ';

                $display_result .= esc_html(implode(', ', $attribute->get_options())) . '</li>';

            }

        }

        $result = '<ul class="bcp-attributes-list">' . $display_result . '</ul>';

        if ($attrCount > 3) {
            $result .= '<span class="bcp-see-more-attr"><i class="bcp-icon-plus"></i><span>' . _e('See More', TEXT_DOMAIN) . '</span></span>';
        }

        echo json_encode($result);
    }

    protected function renderCategoriesQuery($settings): array
    {
        $custom_categories = $settings['selected_categories'];
        $category_items = [];

        if (!empty($custom_categories)) {
            foreach ($custom_categories as $item) {
                if (!empty($item['category_id'])) {
                    $parts = explode('|', $item['category_id']);
                    $cat_id = (int)$parts[0];
                    $icon = isset($item['icon']) ? $item['icon'] : null;
                    $category_items[] = [
                        'id' => $cat_id,
                        'icon' => $icon,
                    ];
                }
            }
        }

        if (empty($category_items)) {
            return [];
        }

        $unique_ids = array_unique(array_column($category_items, 'id'));

        $args = array(
            'taxonomy' => 'product_cat',
            'include' => $unique_ids,
            'orderby' => 'include',
            'hide_empty' => false,
        );

        $terms = get_terms($args);

        if (is_wp_error($terms) || empty($terms)) {
            return [];
        }

        $terms_by_id = [];
        foreach ($terms as $term) {
            $terms_by_id[$term->term_id] = $term;
        }

        $ordered_categories = [];
        foreach ($category_items as $item) {
            $id = $item['id'];
            if (isset($terms_by_id[$id])) {
                $ordered_categories[] = [
                    'term' => $terms_by_id[$id],
                    'icon' => $item['icon'],
                ];
            }
        }

        return $ordered_categories;
    }

    public function render_query($term)
    {
        $settings = $this->get_settings();

        $exclude_products = ($settings['exclude_products']) ? explode(',', $settings['exclude_products']) : [];

        $query_args = array(
            'post_type' => 'product',
            'post_status' => 'publish',
            'posts_per_page' => $settings['posts_per_page'],
            'ignore_sticky_posts' => 1,
            'meta_query' => [],
            'tax_query' => ['relation' => 'AND'],
            'order' => $settings['order'],
            'post__not_in' => $exclude_products,
        );
        $taxonomies = get_object_taxonomies('product', 'objects');
        foreach ($taxonomies as $object) {
            if (!empty($settings[$object->name])) {
                $query_args['tax_query'] = array(
                    array(
                        'taxonomy' => $object->name,
                        'terms' => $settings[$object->name],
                    )
                );
            }
        }

        $product_visibility_term_ids = wc_get_product_visibility_term_ids();

        $query_args['tax_query'][] = array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => $term,
            'post__not_in' => $exclude_products,
        );

        if ('yes' == $settings['hide_free']) {
            $query_args['meta_query'][] = array(
                'key' => '_price',
                'value' => 0,
                'compare' => '>',
                'type' => 'DECIMAL',
            );
        }

        if ('yes' == $settings['hide_out_stock']) {
            $query_args['tax_query'][] = array(
                array(
                    'taxonomy' => 'product_visibility',
                    'field' => 'term_taxonomy_id',
                    'terms' => $product_visibility_term_ids['outofstock'],
                    'operator' => 'NOT IN',
                ),
            ); // WPCS: slow query ok.
        }


        switch ($settings['show_product_type']) {
            case 'featured':
                $query_args['tax_query'][] = array(
                    'taxonomy' => 'product_visibility',
                    'field' => 'term_taxonomy_id',
                    'terms' => $product_visibility_term_ids['featured'],
                );
                break;
            case 'onsale':
                $product_ids_on_sale = wc_get_product_ids_on_sale();
                $product_ids_on_sale[] = 0;
                $query_args['post__in'] = $product_ids_on_sale;
                break;
        }

        switch ($settings['orderby']) {
            case 'price':
                $query_args['meta_key'] = '_price'; // WPCS: slow query ok.
                $query_args['orderby'] = 'meta_value_num';
                break;
            case 'rand':
                $query_args['orderby'] = 'rand';
                break;
            case 'sales':
                $query_args['meta_key'] = 'total_sales'; // WPCS: slow query ok.
                $query_args['orderby'] = 'meta_value_num';
                break;
            default:
                $query_args['orderby'] = 'date';
        }

        $wp_query = new \WP_Query($query_args);

        return $wp_query;
    }

    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $tabDirection = $settings['tab_direction'];

        // products
        $titleTag = $settings['title_tag'];
        $contentAlign = $settings['content_align'];
        $showQuickViewBtn = $settings['show_quick_view'] == 'yes';
        $showRating = $settings['show_rating'] == 'yes';
        $showTitle = $settings['show_title'] == 'yes';
        $freePriceText = $settings['free_text'];

        // grid
        $col = 'col-lg-' . $settings['col'] . ' col-md-' . $settings['col_tablet'] . ' col-' . $settings['col_mobile'];
        $tabsAlign = $settings['tabs_align'];

        // section button link
        if (!empty($settings['section_btn_link']['url'])) {
            $this->add_link_attributes('section_btn_link', $settings['section_btn_link']);
        }

        $selectedCats = $this->renderCategoriesQuery($settings);
        if (!is_wp_error($selectedCats)) {
            if (!empty($selectedCats)) {
                // section
                echo "<div class='bcp-tabs'>";
                echo "<div class='bcp-tabs-head'>";
                echo "<div class='bcp-tabs-nav $tabsAlign'>";

                foreach ($selectedCats as $key => $catData){
                    $cat = $catData['term'];
                    $icon = $catData['icon'];
                    $active = '';
                    if ($key === array_key_first($selectedCats)) $active = 'active';
                    echo "<span class='bcp-tabs-nav-item $tabDirection $active' bcp-data-tab-id='$cat->term_id'>";
                    // Output the icon
                    if (!empty($icon)) {
                        \Elementor\Icons_Manager::render_icon($icon, [ 'aria-hidden' => 'true' ]);
                    }
                    echo " $cat->name</span>";
                }
                echo "</div>";
                echo "</div>";
                echo "<div class='bcp-tabs-content'>";

                foreach ($selectedCats as $key => $catData) {
                    $cat = $catData['term'];
                    $active = '';
                    if ($key === array_key_first($selectedCats)) $active = 'active';
                    echo "<div class='bcp-tab-content $active' id='$cat->term_id'>";
                    echo "<div class='row'>";

                    // get query
                    $wp_query = $this->render_query($cat->slug);
                    if ($wp_query->have_posts()) {

                        while ($wp_query->have_posts()): $wp_query->the_post();
                            $product = wc_get_product($wp_query->post->ID); ?>
                            <div class='<?php echo $col ?>'>
                                <div class="product-card product-card-3 <?php echo ($this->is_product_in_stock($product)) ? '' : 'product-card-unavailable' ?>">
                                    <div class="product-card-image">
                                        <!-- thumbnail -->
                                        <a href="<?php the_permalink() ?>">
                                            <?php if (has_post_thumbnail()) {
                                                the_post_thumbnail($settings['image_size']);
                                            } else { ?>
                                                <img src="<?php echo esc_url(get_template_directory_uri() . '/images/default.jpg'); ?>"
                                                     alt="<?php the_title(); ?>">
                                            <?php } ?>
                                        </a>
                                    </div>
                                    <div class="product-card-content <?php echo $contentAlign ?>">
                                        <!-- title -->
                                        <?php if ($showTitle): ?>
                                            <a href="<?php the_permalink() ?>">
                                                <?php echo "<$titleTag class='title'>"; ?>
                                                <?php the_title(); ?>
                                                <?php echo "</$titleTag>"; ?>
                                            </a>
                                        <?php endif; ?>

                                        <!-- rating -->
                                        <?php if ($showRating): echo $this->bcp_wc_get_rating_html($product->get_average_rating()); endif; ?>

                                        <!-- price -->
                                        <?php $this->render_price($product,$freePriceText); ?>

                                        <div class="product-card-3-buttons">
                                            <!-- add to cart -->
                                            <?php if ($this->is_product_in_stock($product)  && floatval($product->get_price()) != 0): ?>
                                                <?php if ($product->is_type('variable')): ?>
                                                    <a href="<?php the_permalink() ?>" class="product-card-3-cart">
                                                        <span class="product-card-3-cart-icon"><i class="iconly-Buy"></i></span>
                                                        <span class="card-3-btn-title"><?php _e('Add to shopping', TEXT_DOMAIN); ?></span>
                                                    </a>
                                                <?php else: ?>
                                                    <span class="product-card-3-cart ajax-add-to-cart"
                                                          data-product-id="<?php echo esc_attr($product->get_id()); ?>">
                                    <span class="product-card-3-cart-icon"><i class="iconly-Buy"></i></span>
                                    <span class="card-3-btn-title"><?php _e('Add to shopping', TEXT_DOMAIN); ?></span>
                                </span>
                                                <?php endif; ?>
                                            <?php endif; ?>


                                            <!-- quick view -->
                                            <?php if ($showQuickViewBtn):
                                                $excerpt = mb_substr(get_the_excerpt(), 0, 200);
                                                $images = [];
                                                $featuredImg = wp_get_attachment_image_src(get_post_thumbnail_id($product->get_id()), 'single-post-thumbnail');
                                                if ($featuredImg) {
                                                    array_push($images, $featuredImg[0]);
                                                }
                                                $attachment_ids = $product->get_gallery_image_ids();
                                                foreach ($attachment_ids as $attachment_id) {
                                                    $image_link = wp_get_attachment_url($attachment_id);
                                                    array_push($images, $image_link);
                                                }
                                                ?>
                                                <span class="product-card-3-view show-bcp-modal quick-look-button"
                                                      data-bcp-id='<?php echo 'modal-' . $product->get_id(); ?>'
                                                      data-bcp-link='<?php the_permalink() ?>'
                                                      data-bcp-title='<?php the_title(); ?>'
                                                      data-bcp-description='<?php echo esc_attr( wp_strip_all_tags( $excerpt ) ); ?>'
                                                      data-bcp-images='<?php echo json_encode($images); ?>'
                                                      data-bcp-price='<?php echo $this->is_product_in_stock($product) ? json_encode($product->get_price_html()) : ''; ?>'
                                                      data-bcp-attributes='<?php $this->get_attribute_json($product) ?>'
                                                      data-bcp-rating='<?php woocommerce_template_loop_rating(); ?>'
                                                      data-bcp-stock='<?php echo $product->get_stock_status() ?>'>
                                    <i class="iconly-Show"></i><span
                                                            class="card-3-btn-title"><?php _e('Quick view', TEXT_DOMAIN); ?></span>
                                </span>
                                            <?php endif; ?>

                                        </div>

                                    </div>
                                </div>
                            </div>
                        <?php endwhile;

                    } else {
                        echo '<div class="alert alert-info">' . esc_html__('no products found!', TEXT_DOMAIN) . '</div>';
                    }

                    echo "</div>"; // end row
                    echo "</div>"; // end content
                }
                echo "</div>"; // end contents
                echo "</div>"; // end tabs
            }else{
                echo "<div class='bg-dark text-white rounded-2 p-3'>".__('No categories selected.',TEXT_DOMAIN)."</div>";
            }
        }
    }


}

Plugin::instance()->widgets_manager->register_widget_type(new ProductTabs3());