<?php

use Elementor\Widget_Base;
use Elementor\Controls_Manager;

if (!defined('ABSPATH')) exit; // Exit if accessed directly


class Productscarouselsixthstkaveh extends Widget_Base{

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

  public function get_title(){
    return esc_html__( 'Products Carousel Style Six', 'kavehTheme' );
  }

  public function get_icon(){
    return 'eicon-archive-posts';
  }

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

  protected function register_controls(){
    
    $this->start_controls_section(
        'contentproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Element Title', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
      $this->add_control(
        'title2productscarouselsixthstkaveh',
        [
            'label' => esc_html__( 'Main Title', 'kavehTheme' ),
            'type' => \Elementor\Controls_Manager::TEXT,
            'default' => esc_html__( 'Most Popular', 'kavehTheme' ),
    
        ]
    );
    $this->add_control(
      'tagheadingproductscarouselsixthstkaveh',
      [
        'label' => esc_html__( 'Title Tag', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' => 'H3',
        'options' => [
          'H1'  => esc_html__( 'H1', 'kavehTheme' ),
          'H2' => esc_html__( 'H2', 'kavehTheme' ),
          'H3' => esc_html__( 'H3', 'kavehTheme' ),
          'H4' => esc_html__( 'H4', 'kavehTheme' ),
          'H5' => esc_html__( 'H5', 'kavehTheme' ),
          'H6' => esc_html__( 'H6', 'kavehTheme' ),
          'p' => esc_html__( 'p', 'kavehTheme' ),
          'div' => esc_html__( 'div', 'kavehTheme' ),
        ],
      ]
    );
      $this->add_control(
        'titleproductscarouselsixthstkaveh',
        [
            'label' => esc_html__( 'Subtitle', 'kavehTheme' ),
            'type' => \Elementor\Controls_Manager::TEXT,
            'default' => esc_html__( 'Products', 'kavehTheme' ),
    
        ]
    );
      $this->add_control(
        'tagheadingfproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Title Tag', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SELECT,
          'default' => 'H4',
          'options' => [
            'H1'  => esc_html__( 'H1', 'kavehTheme' ),
            'H2' => esc_html__( 'H2', 'kavehTheme' ),
            'H3' => esc_html__( 'H3', 'kavehTheme' ),
            'H4' => esc_html__( 'H4', 'kavehTheme' ),
            'H5' => esc_html__( 'H5', 'kavehTheme' ),
            'H6' => esc_html__( 'H6', 'kavehTheme' ),
            'p' => esc_html__( 'p', 'kavehTheme' ),
            'div' => esc_html__( 'div', 'kavehTheme' ),
          ],
        ]
      );
      $this->add_control(
        'buttonpositionproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Button Display Position', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SELECT,
          'default' => 'bottom',
          'options' => [
            'top'  => esc_html__( 'Top', 'kavehTheme' ),
            'bottom' => esc_html__( 'Bottom', 'kavehTheme' ),
            'none' => esc_html__( 'Hide', 'kavehTheme' ),
          ],
        ]
      );
    $this->add_control(
      'buttonti2productscarouselsixthstkaveh',
      [
          'label' => esc_html__( 'Button Text', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::TEXT,
          'condition' => [
            'buttonpositionproductscarouselsixthstkaveh!' => 'none',
          ],
          'default' => esc_html__( 'View All', 'kavehTheme' ),
  
      ]
  );
  $this->add_control(
    'buttontilink2productscarouselsixthstkaveh',
    [
        'label' => esc_html__( 'Button Link', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::TEXT,
        'condition' => [
          'buttonpositionproductscarouselsixthstkaveh!' => 'none',
        ],
        'default' => esc_html__( '#', 'kavehTheme' ),

    ]
);
    $this->end_controls_section();   
    $this->start_controls_section(
      'content2productscarouselsixthstkaveh',
      [
        'label' => esc_html__( 'Images', 'kavehTheme' ),
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
      ]
    );
    $this->add_control(
      'imgproductscarouselsixthstkaveh',
      [
        'label' => esc_html__( 'Select Your Image', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::MEDIA,
      ]
    );
    
    $this->add_control(
      'imgbgproductscarouselsixthstkaveh',
      [
        'label' => esc_html__( 'Background Image', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::MEDIA,
        'selectors' => [
          '{{WRAPPER}} .popular-products-right' =>
              'background: url({{URL}}) 0 0 no-repeat',
      ],
      ]
    );
    
    $this->end_controls_section();   
  
      $this->start_controls_section(
        'content4productscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Product Settings', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
      $this->add_control(
        'kaveh_exclude_out_of_stock',
        [
          'label' => esc_html__( 'Hide Out of Stock Products', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SWITCHER,
          'yes' => esc_html__( 'Yes', 'kavehTheme' ),
          'no' => esc_html__( 'No', 'kavehTheme' ),
          'return_value' => 'yes',
          'default' => 'yes',
        ]
      );
  $this->add_control(
    'pproductscarouselsixthstkaveh',
    [
      'label' => esc_html__( 'Show Products', 'kavehTheme' ),
      'type' => \Elementor\Controls_Manager::SELECT,
      'default' => 'all',
      'options' => [
        'all'  => esc_html__( 'All', 'kavehTheme' ),
        'cat'  => esc_html__( 'Category', 'kavehTheme' ),

      ],
    ]
    );
    $this->add_control(
      'psortproductscarouselsixthstkaveh',
      [
        'label' => esc_html__( 'Sort Products By', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::SELECT,
        'default' =>'date',
        'options' => [
          'date'  => esc_html__( 'Date', 'kavehTheme' ),
          '_price'  => esc_html__( 'Price', 'kavehTheme' ),
          '_wc_average_rating'  => esc_html__( 'Most Popular', 'kavehTheme' ),
          'total_sales'  => esc_html__( 'Sales Amount', 'kavehTheme' ),
  
        ],
      ]
      );
      $this->add_control(
        'psortiproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Sort Type', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SELECT,
          'default' => 'desc',
          'options' => [
            'asc'  => esc_html__( 'Ascending', 'kavehTheme' ),
            'desc'  => esc_html__( 'Descending', 'kavehTheme' ),
          ],
        ]
        );
  $this->add_control(
    'stylecartproductscarouselsixthstkaveh',
    [
      'label' => esc_html__( 'Product Box Layout', 'kavehTheme' ),
					'type' => \Elementor\Controls_Manager::SELECT,
					'default' => 'one',
					'options' => [
						'one'  => esc_html__( 'Layout One', 'kavehTheme' ),
						'two'  => esc_html__( 'Layout Two', 'kavehTheme' ),
						'three'  => esc_html__( 'Layout Three', 'kavehTheme' ),
						'four'  => esc_html__( 'Layout Four', 'kavehTheme' ),
						'five'  => esc_html__( 'Layout Five', 'kavehTheme' ),
						'six'  => esc_html__( 'Layout Six', 'kavehTheme' ),
						'seven'  => esc_html__( 'Layout Seven', 'kavehTheme' ),
						'eight'  => esc_html__( 'Layout Eight', 'kavehTheme' ),
						'nine'  => esc_html__( 'Layout Nine', 'kavehTheme' ),
						'ten'  => esc_html__( 'Layout Ten', 'kavehTheme' ),
						'eleven'  => esc_html__( 'Layout Eleven', 'kavehTheme' ),
						'twelve'  => esc_html__( 'Layout Twelve', 'kavehTheme' ),
						'thirteen'  => esc_html__( 'Layout Thirteen', 'kavehTheme' ),
						'fourteen'  => esc_html__( 'Layout Fourteen', 'kavehTheme' ),
						'fifteen'  => esc_html__( 'Layout Fifteen', 'kavehTheme' ),
						'sixteen'  => esc_html__( 'Layout Sixteen', 'kavehTheme' ),
						'seventeen'  => esc_html__( 'Layout Seventeen', 'kavehTheme' ),
						'eighteen'  => esc_html__( 'Layout Eighteen', 'kavehTheme' ),
						'nineteen'  => esc_html__( 'Layout Nineteen', 'kavehTheme' ),
						'twenty'  => esc_html__( 'Layout Twenty', 'kavehTheme' ),
						'twenty-one'  => esc_html__( 'Layout Twenty-One', 'kavehTheme' ),
						'twenty-two'  => esc_html__( 'Layout Twenty-Two', 'kavehTheme' ),
						'twenty-three'  => esc_html__( 'Layout Twenty-Three', 'kavehTheme' ),
						'twenty-four'  => esc_html__( 'Layout Twenty-Four', 'kavehTheme' ),
						'twenty-five'  => esc_html__( 'Layout Twenty-Five', 'kavehTheme' ),
						'twenty-six'  => esc_html__( 'Layout Twenty-Six', 'kavehTheme' ),
						'twenty-seven'  => esc_html__( 'Layout Twenty-Seven', 'kavehTheme' ),
						'twenty-eight'  => esc_html__( 'Layout Twenty-Eight', 'kavehTheme' ),
      ],
    ]
    );
  $options5 = array();
$orderby = 'name';
$order = 'asc';
$hide_empty = false ;
$cat_args = array(
    'orderby'    => $orderby,
    'order'      => $order,
    'hide_empty' => $hide_empty,
);

$product_categories = get_terms( 'product_cat', $cat_args );

foreach ( $product_categories as $key => $category ) {
    $options5[$category->term_id] = $category->name;
}
$this->add_control(
    'catproductscarouselsixthstkaveh',
    [
      'label' => esc_html__( 'Select Category', 'kavehTheme' ),
      'type' => \Elementor\Controls_Manager::SELECT2, 
      'multiple' => true,
      'options' => $options5,
      'condition' => [
        'pproductscarouselsixthstkaveh' => 'cat',
      ],
    ]
);
$this->end_controls_section();   
$this->start_controls_section(
  'content5productscarouselsixthstkaveh',
  [
    'label' => esc_html__( 'Carousel Settings', 'kavehTheme' ),
            'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
  ]
);
$this->add_control(
  'showarrowsproductscarouselsixthstkaveh',
  [
    'label' => esc_html__( 'Show Navigation Arrows', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::SWITCHER,
    'yes' => esc_html__( 'Yes', 'kavehTheme' ),
    'no' => esc_html__( 'No', 'kavehTheme' ),
    'return_value' => 'yes',
    'default' => 'yes',
  ]
);
$this->add_control(
  'productnumberproductscarouselsixthstkaveh',
  [
    'label' => esc_html__( 'Number of Products Displayed', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 0,
    'max' => 50,
    'step' => 1,
    'default' => 5,
  ]
);
$this->add_control(
  'productcolumnproductscarouselsixthstkaveh',
  [
    'label' => esc_html__( 'Number of Product Columns on Desktop', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 0,
    'max' => 5,
    'step' => 0.5,
    'default' => 3,

  ]
); 
$this->add_control(
  'productcolumn2productscarouselsixthstkaveh',
  [
    'label' => esc_html__( 'Number of Product Columns on Tablet', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 0,
    'max' => 5,
    'step' => 0.5,
    'default' => 2,

  ]
);
$this->add_control(
  'productcolumn3productscarouselsixthstkaveh',
  [
    'label' => esc_html__( 'Number of Product Columns on Mobile', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 0,
    'max' => 5,
    'step' => 0.5,
    'default' => 1.5,

  ]
);
       $this->end_controls_section();
       $this->start_controls_section(
        'style_productscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Title Styles', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'textcolor2productscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Main Title Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}}  .popular-products-right .title' => 'color: {{VALUE}} !important;',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'title_productscarouselsixthstkaveh',
          'label' => esc_html__( 'Main Title Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}}  .popular-products-right .title',
        ]
      );
      $this->add_control(
        'textcolor3productscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Subtitle Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}}  .popular-products-right .sub-title' => 'color: {{VALUE}} !important;',
          ],
        ]
      ); 
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'title2_productscarouselsixthstkaveh',
          'label' => esc_html__( 'Subtitle Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .popular-products-right .sub-title',
        ]
      );
      $this->end_controls_section();
      $this->start_controls_section(
        'styleb_productscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Button Styles', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'button_productscarouselsixthstkaveh',
          'label' => esc_html__( 'Button Text Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .popular-products-right .btn',
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Text_Shadow::get_type(),
        [
          'name' => 'text_shadowproductscarouselsixthstkaveh',
          'label' => esc_html__( 'Text Shadow', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .popular-products-right .btn',
        ]
      );
      $this->start_controls_tabs(
        'style_tabsproductscarouselsixthstkaveh'
      );
    
      $this->start_controls_tab(
        'style_normal_tabproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Normal', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbuttoncolorproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Button Text Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .popular-products-right .btn' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttoncolorproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Button Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .popular-products-right .btn' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttonradiusproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Button Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .popular-products-right .btn' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Border::get_type(),
        [
          'name' => 'borderproductscarouselsixthstkaveh',
          'label' => esc_html__( 'Border', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .popular-products-right .btn',
        ]
      );
      $this->add_control(
        'buttonbordersproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Border Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'condition' => [
            'borderproductscarouselsixthstkaveh!' => '',
          ],
          'selectors' => [
            '{{WRAPPER}} .popular-products-right .btn' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->end_controls_tab();
      $this->start_controls_tab(
        'style_hove_tabproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Hover', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbuttoncolorhoverproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Button Text Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .popular-products-right .btn:hover' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttoncolorhoverproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Button Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .popular-products-right .btn:hover' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttonradiushoverproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Button Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .popular-products-right .btn:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Border::get_type(),
        [
          'name' => 'borderhoverproductscarouselsixthstkaveh',
          'label' => esc_html__( 'Border', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .popular-products-right .btn:hover',
        ]
      );
      $this->add_control(
        'buttonbordershoverproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Border Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'condition' => [
            'borderhoverproductscarouselsixthstkaveh!' => '',
          ],
          'selectors' => [
            '{{WRAPPER}} .popular-products-right .btn:hover' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->end_controls_tab();
      $this->end_controls_tabs();
      $this->add_group_control(
        \Elementor\Group_Control_Box_Shadow::get_type(),
        [
          'name' => 'box_shadowproductscarouselsixthstkaveh',
          'label' => esc_html__( 'Button Shadow', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .popular-products-right .btn',
        ]
      );
      $this->add_control(
        'hr2productscarouselsixthstkaveh',
        [
          'type' => \Elementor\Controls_Manager::DIVIDER,
        ]
      );
      $this->add_control(
        'buttonpaddingproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Padding', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .popular-products-right .btn' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
          ],
        ]
      );
      $this->end_controls_section();
      $this->start_controls_section(
        'style3_productscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Box Styles', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'borderradiusproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Box Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .popular-products-right' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
          ],
        ]
      );
      $this->add_control(
        'boxcolorproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Box Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}}  .popular-products-right' => 'background-color: {{VALUE}} !important;',
          ],
        ]
      ); 
      $this->add_control(
        'imagewidth3productscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Image Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => [ 'px' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 2000,
              'step' => 5,
            ],
            '%' => [
              'min' => 0,
              'max' => 100,
            ],
          ],
          'selectors' => [
            '{{WRAPPER}} .imgcarouselsix' => 'width: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      $this->add_control(
        'imageheight3amazingoffersecondstkaveh',
        [
          'label' => esc_html__( 'Image Height', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => [ 'px' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 2000,
              'step' => 5,
            ],
            '%' => [
              'min' => 0,
              'max' => 100,
            ],
          ],
          'selectors' => [
            '{{WRAPPER}} .imgcarouselsix' => 'height: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      
      $this->end_controls_section();
      $this->start_controls_section(
        'style5_productscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Carousel Arrow Styles', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
          'condition' => [
            'showarrowsproductscarouselsixthstkaveh' => 'yes',
          ],
        ]
      );
      $this->add_control(
        'arrowscolorproductscarouselsixthstkaveh',
        [
          'label' => esc_html__( 'Carousel Arrow Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .popular-products-left .swiper-button-next::after' => 'color: {{VALUE}} !important;',
            '{{WRAPPER}}  .popular-products-left .swiper-button-prev::after' => 'color: {{VALUE}} !important;',
          ],
        ]
      ); 
      $this->end_controls_section();

      // Add carousel settings section
      $this->start_controls_section(
        'carousel_settings',
        [
          'label' => esc_html__('Carousel Settings', 'kavehTheme'),
          'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );

      $this->add_control(
        'showarrowsproductscarouselsixthstkaveh',
        [
          'label' => esc_html__('Show Navigation Arrows', 'kavehTheme'),
          'type' => \Elementor\Controls_Manager::SWITCHER,
          'label_on' => esc_html__('Yes', 'kavehTheme'),
          'label_off' => esc_html__('No', 'kavehTheme'),
          'return_value' => 'yes',
          'default' => 'yes',
        ]
      );

      $this->add_control(
        'loopproductscarouselsixthstkaveh',
        [
          'label' => esc_html__('Infinite Loop', 'kavehTheme'),
          'type' => \Elementor\Controls_Manager::SWITCHER,
          'label_on' => esc_html__('Yes', 'kavehTheme'),
          'label_off' => esc_html__('No', 'kavehTheme'),
          'return_value' => 'yes',
          'default' => 'yes',
        ]
      );

      $this->add_control(
        'autoplayproductscarouselsixthstkaveh',
        [
          'label' => esc_html__('Autoplay', 'kavehTheme'),
          'type' => \Elementor\Controls_Manager::SWITCHER,
          'label_on' => esc_html__('Yes', 'kavehTheme'),
          'label_off' => esc_html__('No', 'kavehTheme'),
          'return_value' => 'yes',
          'default' => 'no',
        ]
      );

      $this->add_control(
        'autoplaydelayproductscarouselsixthstkaveh',
        [
          'label' => esc_html__('Autoplay Delay (milliseconds)', 'kavehTheme'),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 1000,
          'max' => 10000,
          'step' => 100,
          'default' => 3000,
          'condition' => [
            'autoplayproductscarouselsixthstkaveh' => 'yes',
          ],
        ]
      );

      $this->add_control(
        'showdotsproductscarouselsixthstkaveh',
        [
          'label' => esc_html__('Show Navigation Dots', 'kavehTheme'),
          'type' => \Elementor\Controls_Manager::SWITCHER,
          'label_on' => esc_html__('Yes', 'kavehTheme'),
          'label_off' => esc_html__('No', 'kavehTheme'),
          'return_value' => 'yes',
          'default' => 'no',
        ]
      );

      $this->end_controls_section();

        }
 

  protected function render(){
    $settings = $this->get_settings_for_display();
    $widget_id = $this->get_id();

    // Build swiper settings array
    $swiper_settings = array(
      'navigation' => array(
        'nextEl' => '.swiper-button-next',
        'prevEl' => '.swiper-button-prev'
      ),
      'breakpoints' => array(
        320 => array(
          'slidesPerView' => (int) $settings['productcolumn3productscarouselsixthstkaveh'],
          'spaceBetween' => 4
        ),
        450 => array(
          'slidesPerView' => (int) $settings['productcolumn2productscarouselsixthstkaveh'],
          'spaceBetween' => 12
        ),
        992 => array(
          'slidesPerView' => (int) $settings['productcolumnproductscarouselsixthstkaveh'],
          'spaceBetween' => 20
        ),
        1200 => array(
          'slidesPerView' => (int) $settings['productcolumnproductscarouselsixthstkaveh'],
          'spaceBetween' => 30
        )
      )
    );

    // Add optional settings
    if (isset($settings['loopproductscarouselsixthstkaveh']) && $settings['loopproductscarouselsixthstkaveh'] === 'yes') {
      $swiper_settings['loop'] = true;
    }

    if (isset($settings['autoplayproductscarouselsixthstkaveh']) && $settings['autoplayproductscarouselsixthstkaveh'] === 'yes') {
      $swiper_settings['autoplay'] = array(
        'delay' => isset($settings['autoplaydelayproductscarouselsixthstkaveh']) ? (int) $settings['autoplaydelayproductscarouselsixthstkaveh'] : 3000,
        'disableOnInteraction' => false
      );
    }

    if (isset($settings['showdotsproductscarouselsixthstkaveh']) && $settings['showdotsproductscarouselsixthstkaveh'] === 'yes') {
      $swiper_settings['pagination'] = array(
        'el' => '.swiper-pagination',
        'type' => 'bullets',
        'clickable' => true
      );
    }

    // Properly encode and escape JSON
    $swiper_json = wp_json_encode($swiper_settings, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    ?>
    <section class="popular-products <?php if('top'===$settings['buttonpositionproductscarouselsixthstkaveh']){ ?>popular-products-two <?php } ?>">
      <div class="container d-flex flex-column flex-sm-row position-relative">
        <div class="popular-products-right position-relative w-100 overflow-hidden">
          <<?php echo esc_attr($settings['tagheadingproductscarouselsixthstkaveh']); ?> class="title text-white"><?php echo esc_html($settings['title2productscarouselsixthstkaveh']); ?></<?php echo esc_attr($settings['tagheadingproductscarouselsixthstkaveh']); ?>>
          <<?php echo esc_attr($settings['tagheadingfproductscarouselsixthstkaveh']); ?> class="sub-title text-white"><?php echo esc_html($settings['titleproductscarouselsixthstkaveh']); ?></<?php echo esc_attr($settings['tagheadingfproductscarouselsixthstkaveh']); ?>>
          <?php if('none'!==$settings['buttonpositionproductscarouselsixthstkaveh']){ ?>
          <a href="<?php echo esc_url($settings['buttontilink2productscarouselsixthstkaveh']); ?>"
            class="btn btn-outline-light d-flex align-items-center justify-content-center d-block ms-auto rounded-pill">
            <?php echo esc_html($settings['buttonti2productscarouselsixthstkaveh']); ?></a>
          <?php } ?>
          <img src="<?php echo esc_url($settings['imgproductscarouselsixthstkaveh']['url']); ?>" alt="<?php echo esc_attr(\Elementor\Control_Media::get_image_alt($settings['imgproductscarouselsixthstkaveh'])); ?>" width="218" height="230"
            class="position-absolute start-50 bottom-0 translate-middle-x imgcarouselsix">
        </div>
        <div class="popular-products-left w-100 position-relative">
          <div class="swiper swiper-popular-products" data-swiper='<?php echo esc_attr($swiper_json); ?>'>
            <div class="swiper-wrapper">
              <?php if('cat'===$settings['pproductscarouselsixthstkaveh']){ ?>
                 <?php
                  // Define your custom query arguments
                  $query_args = array(
                    'post_type' => array('product'),
'post_status' => array('publish'),
                    'posts_per_page' => $settings['productnumberproductscarouselsixthstkaveh'],
                    'orderby' => $settings['psortproductscarouselsixthstkaveh'] === 'date' ? 'date' : 'meta_value_num', // Default to date or meta value
                    'order' => $settings['psortiproductscarouselsixthstkaveh'],
                    'tax_query' => array(
                      'relation' => 'AND',
                      array(
                        'taxonomy' => 'product_cat',
                        'field' => 'term_id',
                        'terms' => $settings['catproductscarouselsixthstkaveh'],
                      ),
                    ),
                  );
                  // Handle specific orderby values
                  switch ($settings['psortproductscarouselsixthstkaveh']) {
                    case '_price':
                      $query_args['meta_key'] = '_price';
                      $query_args['orderby'] = 'meta_value_num';
                      break;

                    case '_wc_average_rating':
                      $query_args['meta_key'] = '_wc_average_rating';
                      $query_args['orderby'] = 'meta_value_num';
                      break;

                    case 'total_sales':
                      $query_args['meta_key'] = 'total_sales';
                      $query_args['orderby'] = 'meta_value_num';
                      break;
                  }

                  if ("yes" === $settings['kaveh_exclude_out_of_stock']) {
                    $query_args['tax_query'][] = array(
                      'taxonomy' => 'product_visibility',
                      'field' => 'name',
                      'terms' => array('outofstock'),
                      'operator' => 'NOT IN'
                    );
                  }
                  // Get the cached query results
                  $cached_query = KavehCustomQuery::get_cached_query($query_args);
                  if ($cached_query->have_posts()):
                    while ($cached_query->have_posts()):
                      $cached_query->the_post();
                      ?>
                      <div class="swiper-slide h-auto">
                        <?php $styleproduct2 = $settings['stylecartproductscarouselsixthstkaveh']; ?>
                        <?php get_template_part("template-part/product-cart-$styleproduct2"); ?>
                      </div>
                      <?php
                    endwhile;
                    wp_reset_postdata();
                  else:
                    echo 'No posts found.';
                  endif;
                  ?>

                <?php }elseif('all'===$settings['pproductscarouselsixthstkaveh']){
                ?>

<?php
                  // Define your custom query arguments
                  $query_args = array(
                    'post_type' => array('product'),
'post_status' => array('publish'),
                    'posts_per_page' => $settings['productnumberproductscarouselsixthstkaveh'],
                    'orderby' => $settings['psortproductscarouselsixthstkaveh'] === 'date' ? 'date' : 'meta_value_num', // Default to date or meta value
                    'order' => $settings['psortiproductscarouselsixthstkaveh'],
                    'tax_query' => array(
                      'relation' => 'AND',

                    ),
                  );
                  // Handle specific orderby values
                  switch ($settings['psortproductscarouselsixthstkaveh']) {
                    case '_price':
                      $query_args['meta_key'] = '_price';
                      $query_args['orderby'] = 'meta_value_num';
                      break;

                    case '_wc_average_rating':
                      $query_args['meta_key'] = '_wc_average_rating';
                      $query_args['orderby'] = 'meta_value_num';
                      break;

                    case 'total_sales':
                      $query_args['meta_key'] = 'total_sales';
                      $query_args['orderby'] = 'meta_value_num';
                      break;
                  }

                  if ("yes" === $settings['kaveh_exclude_out_of_stock']) {
                    $query_args['tax_query'][] = array(
                      'taxonomy' => 'product_visibility',
                      'field' => 'name',
                      'terms' => array('outofstock'),
                      'operator' => 'NOT IN'
                    );
                  }
                  // Get the cached query results
                  $cached_query = KavehCustomQuery::get_cached_query($query_args);
                  if ($cached_query->have_posts()):
                    while ($cached_query->have_posts()):
                      $cached_query->the_post();
                      ?>
                      <div class="swiper-slide h-auto">
                        <?php $styleproduct2 = $settings['stylecartproductscarouselsixthstkaveh']; ?>
                        <?php get_template_part("template-part/product-cart-$styleproduct2"); ?>
                      </div>
                      <?php
                    endwhile;
                    wp_reset_postdata();
                  else:
                    echo 'No posts found.';
                  endif;
                  ?>
       
                <?php } ?>
            </div>
            <?php if('yes'===$settings['showarrowsproductscarouselsixthstkaveh']){ ?>
            <div class="swiper-button-next"></div>
            <div class="swiper-button-prev"></div>
            <?php } ?>
          </div>
        </div>
      </div>
    </section>
    <style>
      .popular-products-right{
      background-size: cover !important;
      }
	    @media only screen and (max-width: 575px){
		  .popular-products-right img {
			  width: auto !important;
		  }
	    }
    </style>
     
    <?php
  }


}
