<?php



use Elementor\Widget_Base;
use Elementor\Controls_Manager;

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


class Productscarouselninthstkaveh extends Widget_Base{

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

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

  public function get_categories(){
    return ['kavehelements'];
  }
 
  protected function register_controls(){
    
    $this->start_controls_section(
        'contentproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Title Settings', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
    
      $this->add_control(
          'titleproductscarouselninthstkaveh',
          [
              'label' => esc_html__( 'Title', 'kavehTheme' ),
			'type' => \Elementor\Controls_Manager::TEXT,
			'default' => esc_html__( 'Best Selling Products', 'kavehTheme' ),
      
          ]
      );
      $this->add_control(
        'tagheadingproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Title Tag', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SELECT,
          'default' => 'H2',
          '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' ),
            'span' => esc_html__( 'span', 'kavehTheme' ),
          ],
        ]
      );
      $this->add_control(
        'title3productscarouselninthstkaveh',
        [
            'label' => esc_html__( 'Bold Subtitle', 'kavehTheme' ),
			'type' => \Elementor\Controls_Manager::TEXT,
			'default' => esc_html__( 'Special Sale', 'kavehTheme' ),
    
        ]
    );
      $this->add_control(
        'title2productscarouselninthstkaveh',
        [
            'label' => esc_html__( 'Subtitle', 'kavehTheme' ),
			'type' => \Elementor\Controls_Manager::TEXT,
			'default' => esc_html__( 'Holiday Night', 'kavehTheme' ),
    
        ]
    );
    $this->add_control(
      'tag2headingproductscarouselninthstkaveh',
      [
        'label' => esc_html__( 'Subtitle 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' ),
          'span' => esc_html__( 'span', 'kavehTheme' ),
        ],
      ]
    );
    $this->add_control(
      'showbutton1productscarouselninthstkaveh',
      [
        'label' => esc_html__( 'Show Button?', 'kavehTheme' ),
			'type' => \Elementor\Controls_Manager::SWITCHER,
			'yes' => esc_html__( 'Yes', 'kavehTheme' ),
			'no' => esc_html__( 'No', 'kavehTheme' ),
        'return_value' => 'yes',
        'default' => 'yes',
      ]
      );
      $this->add_control(
        'buttons2productscarouselninthstkaveh',
        [
            'label' => esc_html__( 'Button Title', 'kavehTheme' ),
			'type' => \Elementor\Controls_Manager::TEXT,
			'default' => esc_html__( 'Products', 'kavehTheme' ),
            'condition' => [
              'showbutton1productscarouselninthstkaveh' => 'yes',
            ],
        ]
    );
    $this->add_control(
      'iconbutts2productscarouselninthstkaveh',
      [
        'label' => esc_html__( 'Icon', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::ICONS,
        'skin' => 'inline',
        'condition' => [
          'showbutton1productscarouselninthstkaveh' => 'yes',
        ],
        'exclude_inline_options' => [ 'svg' ],
        'default' => [
          'value' => 'icon-eye-2',
        ],
      ]
    );
    $this->add_control(
      'linkbuttons2productscarouselninthstkaveh',
      [
          'label' => esc_html__( 'Button Link', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::TEXT,
          'condition' => [
              'showbutton1productscarouselninthstkaveh' => 'yes',
            ],
          'default' => esc_html__( '#', 'kavehTheme' ),
  
      ]
  );
  $this->end_controls_section();
  $this->start_controls_section(
    'content2productscarouselninthstkaveh',
    [
      'label' => esc_html__( 'Product Settings', 'kavehTheme' ),
              'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    ]
  );
  $this->add_control(
    'stylecartproductscarouselninthstkaveh',
    [
      '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' ),
        ],
    ]
    );
    $this->add_control(
        'kaveh_exclude_out_of_stock',
        [
          'label' => esc_html__( 'Do not display 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(
        'pproductscarouselninthstkaveh',
        [
          '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(
          'psortproductscarouselninthstkaveh',
          [
            '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(
          'psortiproductscarouselninthstkaveh',
          [
            'label' => esc_html__( 'Sort Type', 'kavehTheme' ),
            'type' => \Elementor\Controls_Manager::SELECT,
            'default' => 'desc',
            'options' => [
              'asc'  => esc_html__( 'Ascending', 'kavehTheme' ),
              'desc'  => esc_html__( 'Descending', 'kavehTheme' ),
            ],
          ]
          );
  $options2 = 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 ) {
    $options2[$category->term_id] = $category->name;
}
$this->add_control(
    'catproductscarouselninthstkaveh',
    [
      'label' => esc_html__( 'Select Category', 'kavehTheme' ),
      'type' => \Elementor\Controls_Manager::SELECT2, 
      'multiple' => true,
      'options' => $options2,
      'condition' => [
        'pproductscarouselninthstkaveh' => 'cat',
      ],
    ]
);
$this->end_controls_section();
$this->start_controls_section(
  'content3productscarouselninthstkaveh',
  [
    'label' => esc_html__( 'Carousel Settings', 'kavehTheme' ),
            'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
  ]
);
$this->add_control(
  'showarrowproductscarouselninthstkaveh',
  [
    'label' => esc_html__( 'Show 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(
  'productnumberproductscarouselninthstkaveh',
  [
    'label' => esc_html__( 'Number of Products Displayed', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 0,
    'max' => 50,
    'step' => 1,
    'default' => 5,
  ]
);
$this->add_control(
  'productcolumnproductscarouselninthstkaveh',
  [
    'label' => esc_html__( 'Number of Product Columns on Desktop', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 0,
    'max' => 5,
    'step' => 1,
    'default' => 4,

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

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

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

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

$this->add_control(
  'pauseonhoverproductscarouselninthstkaveh',
  [
    'label' => esc_html__( 'Pause on Hover', 'kavehTheme' ),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'yes' => esc_html__( 'Yes', 'kavehTheme' ),
				'no' => esc_html__( 'No', 'kavehTheme' ),
    'return_value' => 'yes',
    'default' => 'yes',
    'condition' => [
      'autoplayproductscarouselninthstkaveh' => 'yes',
    ],
  ]
);

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

// Speed settings
$this->add_control(
  'speedproductscarouselninthstkaveh',
  [
    'label' => esc_html__( 'Transition Speed (milliseconds)', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 300,
    'max' => 3000,
    'step' => 100,
    'default' => 300,
  ]
);

// Centered slides
$this->add_control(
  'centeredslidesproductscarouselninthstkaveh',
  [
    'label' => esc_html__( 'Centered Slides', 'kavehTheme' ),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'yes' => esc_html__( 'Yes', 'kavehTheme' ),
				'no' => esc_html__( 'No', 'kavehTheme' ),
    'return_value' => 'yes',
    'default' => 'no',
  ]
);

// Free mode
$this->add_control(
  'freemodeproductscarouselninthstkaveh',
  [
    'label' => esc_html__( 'Free Mode', 'kavehTheme' ),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'yes' => esc_html__( 'Yes', 'kavehTheme' ),
				'no' => esc_html__( 'No', 'kavehTheme' ),
				'return_value' => 'yes',
				'default' => 'no',
				'description' => esc_html__( 'Slides move freely', 'kavehTheme' ),
  ]
);

// Effect
$this->add_control(
  'effectproductscarouselninthstkaveh',
  [
    'label' => esc_html__( 'Transition Effect', 'kavehTheme' ),
				'type' => \Elementor\Controls_Manager::SELECT,
				'default' => 'slide',
				'options' => [
					'slide' => esc_html__( 'Slide', 'kavehTheme' ),
					'fade' => esc_html__( 'Fade', 'kavehTheme' ),
					'cube' => esc_html__( 'Cube', 'kavehTheme' ),
					'coverflow' => esc_html__( 'Coverflow', 'kavehTheme' ),
					'flip' => esc_html__( 'Flip', 'kavehTheme' ),
    ],
  ]
);

// Pagination dots
$this->add_control(
  'showdotsproductscarouselninthstkaveh',
  [
    'label' => esc_html__( 'Show Pagination Dots', 'kavehTheme' ),
				'type' => \Elementor\Controls_Manager::SWITCHER,
				'yes' => esc_html__( 'Yes', 'kavehTheme' ),
				'no' => esc_html__( 'No', 'kavehTheme' ),
    'return_value' => 'yes',
    'default' => 'yes',
  ]
);
       $this->end_controls_section();
       $this->start_controls_section(
        'style_productscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Title Styles', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'textcolor2productscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Main Title Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .section-heading-nine .title-en' => 'color: {{VALUE}}',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'titleproductscarouselninthstkaveh',
          'label' => esc_html__( 'Main Title Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .section-heading-nine .title-en',
        ]
      );
      $this->add_control(
        'textcolor3productscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Bold Subtitle Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .section-heading-nine .title b' => 'color: {{VALUE}}',
          ],
        ]
      );
      $this->add_control(
        'textcolor22productscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Subtitle Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .section-heading-nine .title' => 'color: {{VALUE}}',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'title2productscarouselninthstkaveh',
          'label' => esc_html__( 'Subtitle Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .section-heading-nine .title',
        ]
      );
      $this->end_controls_section();
      $this->start_controls_section(
        'styleb_productscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Button Styles', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
          'condition' => [
            'showbutton1productscarouselninthstkaveh' => 'yes',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'button_nchbproductscarouselninthstkaveh',
          'label' => esc_html__( 'Button Text Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .section-heading-nine a',
        ]
      );
      $this->add_control(
        'iconsizenchbproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Icon Size', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => [ 'px' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 200,
              'step' => 1,
            ],
          ],
          'selectors' => [
            '{{WRAPPER}} .section-heading-nine a i' => 'font-size: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Text_Shadow::get_type(),
        [
          'name' => 'text_shadownchbproductscarouselninthstkaveh',
          'label' => esc_html__( 'Text Shadow', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .section-heading-nine a',
        ]
      );
      $this->start_controls_tabs(
        'style_tabsnchbproductscarouselninthstkaveh'
      );
      
      $this->start_controls_tab(
        'style_normal_tabnchbproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Normal', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbuttoncolornchbproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Button Text Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .section-heading-nine a' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'iconcolornchbproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Icon Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .section-heading-nine a i' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttoncolornchbproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Button Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .section-heading-nine a::before' => 'background-color: {{VALUE}}',

          ],
        ]
      ); 
      
      $this->end_controls_tab();
      $this->start_controls_tab(
        'style_hove_tabnchbproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Hover', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbuttoncolorhovernchbproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Button Text Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .section-heading-nine a:hover' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'iconcolorhovernchbproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Icon Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .section-heading-nine a:hover i' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttoncolorhovernchbproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Button Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .section-heading-nine a::before:hover' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 
      $this->end_controls_tab();
      $this->end_controls_tabs();
      $this->add_control(
        'hr1nchbproductscarouselninthstkaveh',
        [
          'type' => \Elementor\Controls_Manager::DIVIDER,
        ]
      );
      $this->add_control(
        'buttonpaddingnchbproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Padding', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .section-heading-nine a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
          ],
        ]
      );

      $this->end_controls_section();
      $this->start_controls_section(
        'style3_productscarouselninthstkaveh',
        [
          'label' => esc_html__( 'General Styles', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'bgcolorproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .latest-products-book-wrapper' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 

      $this->add_control(
        'bgcoloriconproductscarouselninthstkaveh',
        [
          'label' => esc_html__( 'Arrow Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'condition' => [
            'showarrowproductscarouselninthstkaveh' => 'yes',
          ],
          'selectors' => [
            '{{WRAPPER}} .swiper-button-next::after' => 'color: {{VALUE}}',
            '{{WRAPPER}} .swiper-button-prev::after' => 'color: {{VALUE}}',

          ],
        ]
      ); 
      $this->end_controls_section();
        }


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

<section class="selling-specials-two">
      <div class="container position-relative">
        <!-- Start Heading -->
        <div class="section-heading-nine mx-auto w-100 text-center mb-5">
          <<?php echo  esc_attr($settings['tagheadingproductscarouselninthstkaveh']); ?> class="title-en"><?php echo esc_html($settings['titleproductscarouselninthstkaveh']); ?></<?php echo  esc_attr($settings['tagheadingproductscarouselninthstkaveh']); ?>>
          <<?php echo  esc_attr($settings['tag2headingproductscarouselninthstkaveh']); ?> class="title">
            <b><?php echo esc_html($settings['title3productscarouselninthstkaveh']); ?></b>
            <?php echo esc_html($settings['title2productscarouselninthstkaveh']); ?>
          </<?php echo  esc_attr($settings['tag2headingproductscarouselninthstkaveh']); ?>>
          <?php if("yes"===$settings['showbutton1productscarouselninthstkaveh']){?>
          <a href="<?php echo esc_url($settings['linkbuttons2productscarouselninthstkaveh']); ?>" class="position-relative d-flex align-items-center">
          <?php echo esc_html($settings['buttons2productscarouselninthstkaveh']); ?>
            <i class="<?php echo esc_attr($settings['iconbutts2productscarouselninthstkaveh']['value']); ?> ms-2"></i>
          </a>
          <?php } ?>
        </div>
        <!-- End Heading -->
         
<?php
// Build swiper settings array
$swiper_settings = array(
  'watchSlidesProgress' => true,
  'navigation' => array(
    'nextEl' => '.swiper-button-next',
    'prevEl' => '.swiper-button-prev'
  ),
  'breakpoints' => array(
    320 => array(
      'slidesPerView' => (int)$settings['productcolumn3productscarouselninthstkaveh'],
      'spaceBetween' => 4
    ),
    500 => array(
      'slidesPerView' => (int)$settings['productcolumn2productscarouselninthstkaveh'],
      'spaceBetween' => 12
    ),
    768 => array(
      'slidesPerView' => (int)$settings['productcolumn2productscarouselninthstkaveh'],
      'spaceBetween' => 20
    ),
    992 => array(
      'slidesPerView' => (int)$settings['productcolumnproductscarouselninthstkaveh'],
      'spaceBetween' => 20
    ),
    1200 => array(
      'slidesPerView' => (int)$settings['productcolumnproductscarouselninthstkaveh'],
      'spaceBetween' => 30
    )
  )
);

// Add optional settings only if they exist and are not default
if (isset($settings['loopproductscarouselninthstkaveh']) && $settings['loopproductscarouselninthstkaveh'] === 'yes') {
  $swiper_settings['loop'] = true;
}

if (isset($settings['speedproductscarouselninthstkaveh']) && !empty($settings['speedproductscarouselninthstkaveh'])) {
  $swiper_settings['speed'] = (int)$settings['speedproductscarouselninthstkaveh'];
}

if (isset($settings['centeredslidesproductscarouselninthstkaveh']) && $settings['centeredslidesproductscarouselninthstkaveh'] === 'yes') {
  $swiper_settings['centeredSlides'] = true;
}

if (isset($settings['freemodeproductscarouselninthstkaveh']) && $settings['freemodeproductscarouselninthstkaveh'] === 'yes') {
  $swiper_settings['freeMode'] = true;
}

if (isset($settings['effectproductscarouselninthstkaveh']) && $settings['effectproductscarouselninthstkaveh'] !== 'slide') {
  $swiper_settings['effect'] = $settings['effectproductscarouselninthstkaveh'];
}

// Add autoplay if enabled
if (isset($settings['autoplayproductscarouselninthstkaveh']) && $settings['autoplayproductscarouselninthstkaveh'] === 'yes') {
  $autoplay_settings = array(
    'delay' => isset($settings['autoplaydelayproductscarouselninthstkaveh']) ? (int)$settings['autoplaydelayproductscarouselninthstkaveh'] : 3000,
    'disableOnInteraction' => false
  );
  
  if (isset($settings['pauseonhoverproductscarouselninthstkaveh']) && $settings['pauseonhoverproductscarouselninthstkaveh'] === 'yes') {
    $autoplay_settings['pauseOnMouseEnter'] = true;
  }
  
  $swiper_settings['autoplay'] = $autoplay_settings;
}

// Add pagination if enabled
if (isset($settings['showdotsproductscarouselninthstkaveh']) && $settings['showdotsproductscarouselninthstkaveh'] === '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);
?>

        <!-- Start Carousel -->
        <div class="swiper swiper-selling-specials-two swiper-button-arrow swiper-visible" data-swiper='<?php echo esc_attr($swiper_json); ?>'>
        <div class="swiper-wrapper">
            <?php if('cat'===$settings['pproductscarouselninthstkaveh']){ ?>
                <?php
                // Define your custom query arguments
                $query_args = array(
                  'post_type' => array('product'),
                  'post_status' => array('publish'),
                  'posts_per_page' => $settings['productnumberproductscarouselninthstkaveh'],
                  'orderby' => $settings['psortproductscarouselninthstkaveh'] === 'date' ? 'date' : 'meta_value_num', // Default to date or meta value
                  'order' => $settings['psortiproductscarouselninthstkaveh'],
                  'tax_query' => array(
                    'relation' => 'AND',
                    array(
                      'taxonomy' => 'product_cat',
                      'field' => 'term_id',
                      'terms' => $settings['catproductscarouselninthstkaveh'],
                    ),
                  ),
                );
                // Handle specific orderby values
                switch ($settings['psortproductscarouselninthstkaveh']) {
                  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['stylecartproductscarouselninthstkaveh']; ?>
                      <?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['pproductscarouselninthstkaveh']){
                ?>
              <?php
                // Define your custom query arguments
                $query_args = array(
                  'post_type' => array('product'),
                'post_status' => array('publish'),
                  'posts_per_page' => $settings['productnumberproductscarouselninthstkaveh'],
                  'orderby' => $settings['psortproductscarouselninthstkaveh'] === 'date' ? 'date' : 'meta_value_num', // Default to date or meta value
                  'order' => $settings['psortiproductscarouselninthstkaveh'],
                  'tax_query' => array(
                    'relation' => 'AND',
                  ),
                );
                // Handle specific orderby values
                switch ($settings['psortproductscarouselninthstkaveh']) {
                  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['stylecartproductscarouselninthstkaveh']; ?>
                      <?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['showarrowproductscarouselninthstkaveh']){?>
          <div class="swiper-bottom d-flex align-items-center justify-content-center position-absolute top-0 w-100">
            <div class="swiper-pagination position-relative w-auto h-auto top-0 start-0 bottom-0 end-0 m-0 me-3"></div>
            <div class="swiper-button-prev position-relative w-auto h-auto top-0 start-0 bottom-0 end-0 m-0 me-3"></div>
            <div class="swiper-button-next position-relative w-auto h-auto top-0 start-0 bottom-0 end-0 m-0"></div>
          </div>
          <?php } ?>
            <!-- Start Button -->
            <!-- End Button -->
          </div>
        <!-- End Carousel -->
      </div>
    </section>
    
    <?php
  }


}
