<?php

use Elementor\Widget_Base;
use Elementor\Controls_Manager;

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


class Productsdigistylecarouselsecondstkaveh extends Widget_Base{

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

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

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

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

  protected function register_controls(){
    
    $this->start_controls_section(
        'contentproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Element Title', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
        $this->add_control(
          'buttonti1productsdigistylecarouselsecondstkaveh',
          [
              'label' => esc_html__( 'Title', 'kavehTheme' ),
              'type' => \Elementor\Controls_Manager::TEXT,
              'default' => esc_html__( 'Recent Best Sellers', 'kavehTheme' ),
      
          ]
      );
      $this->add_control(
        'tagheading1productsdigistylecarouselsecondstkaveh',
        [
          '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(
      'buttonti2productsdigistylecarouselsecondstkaveh',
      [
          'label' => esc_html__( 'Button Title', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::TEXT,
          'default' => esc_html__( 'View All', 'kavehTheme' ),
  
      ]
  );
  $this->add_control(
    'buttontilink2productsdigistylecarouselsecondstkaveh',
    [
        'label' => esc_html__( 'Button Link', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => esc_html__( '#', 'kavehTheme' ),

    ]
);
$this->add_control(
  'showticol1productsdigistylecarouselsecondstkaveh',
  [
    'label' => esc_html__( 'Show First Column', '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(
        'content4productsdigistylecarouselsecondstkaveh',
        [
          '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(
    'pproductsdigistylecarouselsecondstkaveh',
    [
      'label' => esc_html__( 'Display Products', 'kavehTheme' ),
      'type' => \Elementor\Controls_Manager::SELECT,
      'default' => 'all',
      'options' => [
        'all'  => esc_html__( 'All', 'kavehTheme' ),
        'cat'  => esc_html__( 'Category', 'kavehTheme' ),

      ],
    ]
    );
    $this->add_control(
      'psortproductsdigistylecarouselsecondstkaveh',
      [
        '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 Volume', 'kavehTheme' ),
  
        ],
      ]
      );
      $this->add_control(
        'psortiproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Sort Order', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SELECT,
          'default' => 'desc',
          'options' => [
            'asc'  => esc_html__( 'Ascending', 'kavehTheme' ),
            'desc'  => esc_html__( 'Descending', '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(
    'catproductsdigistylecarouselsecondstkaveh',
    [
      'label' => esc_html__( 'Select Category', 'kavehTheme' ),
      'type' => \Elementor\Controls_Manager::SELECT2, 
      'multiple' => true,
      'options' => $options5,
      'condition' => [
        'pproductsdigistylecarouselsecondstkaveh' => 'cat',
      ],
    ]
);
$this->end_controls_section();   
$this->start_controls_section(
  'content5productsdigistylecarouselsecondstkaveh',
  [
    'label' => esc_html__( 'Carousel Settings', 'kavehTheme' ),
    'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
  ]
);
$this->add_control(
  'productnumberproductsdigistylecarouselsecondstkaveh',
  [
    'label' => esc_html__( 'Number of Products to Display', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 0,
    'max' => 50,
    'step' => 1,
    'default' => 5,
  ]
);
$this->add_control(
  'productcolumnproductsdigistylecarouselsecondstkaveh',
  [
    '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(
  'productcolumn2productsdigistylecarouselsecondstkaveh',
  [
    '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(
  'productcolumn3productsdigistylecarouselsecondstkaveh',
  [
    'label' => esc_html__( 'Number of Product Columns on Mobile', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 0,
    'max' => 5,
    'step' => 1,
    'default' => 1,
  ]
);
// Autoplay settings
$this->add_control(
  'autoplayproductsdigistylecarouselsecondstkaveh',
  [
    '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(
  'autoplaydelayproductsdigistylecarouselsecondstkaveh',
  [
    'label' => esc_html__( 'Autoplay Delay (milliseconds)', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 1000,
    'max' => 10000,
    'step' => 500,
    'default' => 3000,
    'condition' => [
      'autoplayproductsdigistylecarouselsecondstkaveh' => 'yes',
    ],
  ]
);
$this->add_control(
  'pauseonhoverproductsdigistylecarouselsecondstkaveh',
  [
    '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' => [
      'autoplayproductsdigistylecarouselsecondstkaveh' => 'yes',
    ],
  ]
);
// Loop settings
$this->add_control(
  'loopproductsdigistylecarouselsecondstkaveh',
  [
    '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(
  'speedproductsdigistylecarouselsecondstkaveh',
  [
    '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(
  'centeredslidesproductsdigistylecarouselsecondstkaveh',
  [
    '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(
  'freemodeproductsdigistylecarouselsecondstkaveh',
  [
    '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(
  'effectproductsdigistylecarouselsecondstkaveh',
  [
    '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' ),
    ],
  ]
);
// Show arrows
$this->add_control(
  'showarrowproductsdigistylecarouselsecondstkaveh',
  [
    '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' => 'no',
  ]
);
// Pagination dots
$this->add_control(
  'showdotsproductsdigistylecarouselsecondstkaveh',
  [
    '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' => 'no',
  ]
);
$this->end_controls_section();
       $this->start_controls_section(
        'stylea_productsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Title Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'buttona_productsdigistylecarouselsecondstkaveh',
          'label' => esc_html__( 'Title Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .top-selling-products-digi-right .title',
        ]
      );
      $this->add_control(
        'textabuttoncolorproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Title Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi-right .title' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->end_controls_section();
      $this->start_controls_section(
        'styleb_productsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Button Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'button_productsdigistylecarouselsecondstkaveh',
          'label' => esc_html__( 'Button Text Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .top-selling-products-digi .btn-more',
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Text_Shadow::get_type(),
        [
          'name' => 'text_shadowproductsdigistylecarouselsecondstkaveh',
          'label' => esc_html__( 'Text Shadow', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .top-selling-products-digi .btn-more',
        ]
      );
      $this->start_controls_tabs(
        'style_tabsproductsdigistylecarouselsecondstkaveh'
      );
    
      $this->start_controls_tab(
        'style_normal_tabproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Normal', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbuttoncolorproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Button Text Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi .btn-more' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttoncolorproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Button Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi .btn-more' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttonradiusproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Button Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi .btn-more' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Border::get_type(),
        [
          'name' => 'borderproductsdigistylecarouselsecondstkaveh',
          'label' => esc_html__( 'Border', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .top-selling-products-digi .btn-more',
        ]
      );
      $this->add_control(
        'buttonbordersproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Border Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'condition' => [
            'borderproductsdigistylecarouselsecondstkaveh!' => '',
          ],
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi .btn-more' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->end_controls_tab();
      $this->start_controls_tab(
        'style_hove_tabproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Hover', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbuttoncolorhoverproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Button Text Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi .btn-more:hover' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttoncolorhoverproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Button Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi .btn-more:hover' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttonradiushoverproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Button Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi .btn-more:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Border::get_type(),
        [
          'name' => 'borderhoverproductsdigistylecarouselsecondstkaveh',
          'label' => esc_html__( 'Border', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .top-selling-products-digi .btn-more:hover',
        ]
      );
      $this->add_control(
        'buttonbordershoverproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Border Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'condition' => [
            'borderhoverproductsdigistylecarouselsecondstkaveh!' => '',
          ],
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi .btn-more: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_shadowproductsdigistylecarouselsecondstkaveh',
          'label' => esc_html__( 'Button Shadow', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .top-selling-products-digi .btn-more',
        ]
      );
      $this->add_control(
        'hr2productsdigistylecarouselsecondstkaveh',
        [
          'type' => \Elementor\Controls_Manager::DIVIDER,
        ]
      );
      $this->add_control(
        'buttonpaddingproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Padding', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi .btn-more' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->end_controls_section();
      $this->start_controls_section(
        'style5_productsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Carousel Navigation Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
          'condition' => [
            'showarrowproductsdigistylecarouselsecondstkaveh' => 'yes',

          ],
        ]
      );
      $this->start_controls_tabs(
        'style_tabsarrowproductsdigistylecarouselsecondstkaveh'
      );
    
      $this->start_controls_tab(
        'style_normal_tabarrowproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Normal', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbutton1colorarrowproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Icon Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi-left .swiper-button-next::after' => 'color: {{VALUE}}',
            '{{WRAPPER}} .top-selling-products-digi-left .swiper-button-prev::after' => 'color: {{VALUE}}',

          ],
        ]
      ); 
      $this->add_control(
        'buttoncolorarrowproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi-left .swiper-button-next' => 'background-color: {{VALUE}}',
            '{{WRAPPER}} .top-selling-products-digi-left .swiper-button-prev' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 

      $this->end_controls_tab();
      $this->start_controls_tab(
        'style_hove_tabarrowproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Hover', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbutton1hovercolorarrowproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Icon Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi-left .swiper-button-next:hover::after' => 'color: {{VALUE}}',
            '{{WRAPPER}} .top-selling-products-digi-left .swiper-button-prev:hover::after' => 'color: {{VALUE}}',          ],
        ]
      ); 
      $this->add_control(
        'buttoncolorhoverarrowproductsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .top-selling-products-digi-left .swiper-button-next:hover' => 'background-color: {{VALUE}}',
            '{{WRAPPER}} .top-selling-products-digi-left .swiper-button-prev:hover' => 'background-color: {{VALUE}}',

          ],
        ]
      ); 
      $this->end_controls_tab();
      $this->end_controls_tabs();
      $this->end_controls_section();
      $this->start_controls_section(
        'stylebox_2productsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Product Box Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'boxradi2productsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Box Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .product-fifteen' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->add_control(
        'boxbghov2productsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Product Image Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .product-fifteen .image' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'boxradi2productsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Product Image Background Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .product-fifteen .image' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->add_control(
        'boxpercentage2productsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Discount Percentage Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .product-fifteen .image .offer' => 'background-color: {{VALUE}}',

          ],
        ]
      ); 
      $this->add_control(
        'boxbgpercentage2productsdigistylecarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Discount Percentage Text Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .product-fifteen .image .offer' => 'color: {{VALUE}} !important',

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

        }
 

  protected function render(){
    $settings = $this->get_settings_for_display();
    $clsid = $this->get_id();
    // Build swiper settings array
    $swiper_settings = array(
      'watchSlidesProgress' => true,
      'breakpoints' => array(
        320 => array(
          'slidesPerView' => (int) $settings['productcolumn3productsdigistylecarouselsecondstkaveh'],
          'spaceBetween' => 12
        ),
        576 => array(
          'slidesPerView' => (int) $settings['productcolumn3productsdigistylecarouselsecondstkaveh'],
          'spaceBetween' => 12
        ),
        768 => array(
          'slidesPerView' => (int) $settings['productcolumn2productsdigistylecarouselsecondstkaveh'],
          'spaceBetween' => 12
        ),
        992 => array(
          'slidesPerView' => (int) $settings['productcolumnproductsdigistylecarouselsecondstkaveh'],
          'spaceBetween' => 16
        ),
        1200 => array(
          'slidesPerView' => (int) $settings['productcolumnproductsdigistylecarouselsecondstkaveh'],
          'spaceBetween' => 24
        )
      )
    );
    // Add navigation if arrows are enabled
    if (isset($settings['showarrowproductsdigistylecarouselsecondstkaveh']) && $settings['showarrowproductsdigistylecarouselsecondstkaveh'] === 'yes') {
      $swiper_settings['navigation'] = array(
        'nextEl' => '.swiper-button-next',
        'prevEl' => '.swiper-button-prev'
      );
    }
    // Add optional settings only if they exist and are not default
    if (isset($settings['loopproductsdigistylecarouselsecondstkaveh']) && $settings['loopproductsdigistylecarouselsecondstkaveh'] === 'yes') {
      $swiper_settings['loop'] = true;
    }
    if (isset($settings['speedproductsdigistylecarouselsecondstkaveh']) && !empty($settings['speedproductsdigistylecarouselsecondstkaveh'])) {
      $swiper_settings['speed'] = (int) $settings['speedproductsdigistylecarouselsecondstkaveh'];
    }
    if (isset($settings['centeredslidesproductsdigistylecarouselsecondstkaveh']) && $settings['centeredslidesproductsdigistylecarouselsecondstkaveh'] === 'yes') {
      $swiper_settings['centeredSlides'] = true;
    }
    if (isset($settings['freemodeproductsdigistylecarouselsecondstkaveh']) && $settings['freemodeproductsdigistylecarouselsecondstkaveh'] === 'yes') {
      $swiper_settings['freeMode'] = true;
    }
    if (isset($settings['effectproductsdigistylecarouselsecondstkaveh']) && $settings['effectproductsdigistylecarouselsecondstkaveh'] !== 'slide') {
      $swiper_settings['effect'] = $settings['effectproductsdigistylecarouselsecondstkaveh'];
    }
    // Add autoplay if enabled
    if (isset($settings['autoplayproductsdigistylecarouselsecondstkaveh']) && $settings['autoplayproductsdigistylecarouselsecondstkaveh'] === 'yes') {
      $autoplay_settings = array(
        'delay' => isset($settings['autoplaydelayproductsdigistylecarouselsecondstkaveh']) ? (int) $settings['autoplaydelayproductsdigistylecarouselsecondstkaveh'] : 3000,
        'disableOnInteraction' => false
      );
      if (isset($settings['pauseonhoverproductsdigistylecarouselsecondstkaveh']) && $settings['pauseonhoverproductsdigistylecarouselsecondstkaveh'] === 'yes') {
        $autoplay_settings['pauseOnMouseEnter'] = true;
      }
      $swiper_settings['autoplay'] = $autoplay_settings;
    }
    // Add pagination if enabled
    if (isset($settings['showdotsproductsdigistylecarouselsecondstkaveh']) && $settings['showdotsproductsdigistylecarouselsecondstkaveh'] === '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="top-selling-products-digi">
      <div class="container d-flex flex-column flex-md-row">
      <?php if("yes"===$settings['showticol1productsdigistylecarouselsecondstkaveh']){?>
        <!-- Start Title -->
        <div
          class="top-selling-products-digi-right d-flex flex-column align-items-center align-items-md-end w-100 mb-4 mb-md-0">
          <<?php echo  esc_attr($settings['tagheading1productsdigistylecarouselsecondstkaveh']); ?> class="title mb-0"><?php echo esc_html($settings['buttonti1productsdigistylecarouselsecondstkaveh']); ?></<?php echo  esc_attr($settings['tagheading1productsdigistylecarouselsecondstkaveh']); ?>>
          <a href="<?php echo  esc_url($settings['buttontilink2productsdigistylecarouselsecondstkaveh']); ?>" class="btn btn-outline-dark-3 btn-more d-none d-md-block"> <?php echo  esc_html($settings['buttonti2productsdigistylecarouselsecondstkaveh']); ?></a>
        </div>
        <!-- End Title -->
        <?php }else{ ?>
        <style>
          .digi-amazing-left, .top-selling-products-digi-left {
            max-width: 100% !important;
        }
        </style>
          <?php } ?>
        <!-- Start Products -->
        <div class="top-selling-products-digi-left w-100">
          <!-- Start Carousel -->
          <div class="swiper swiper-top-selling-products-digi position-relative overflow-hidden" data-swiper='<?php echo esc_attr($swiper_json); ?>'>
            <div class="swiper-wrapper">

            <?php if('cat'===$settings['pproductsdigistylecarouselsecondstkaveh']){ ?>
              <?php 
                  
                  // WP_Query args
                  $q_pc2_query_args = array(
                    'post_type' => array('product'),
'post_status' => array('publish'),
                    'posts_per_page' => $settings['productnumberproductsdigistylecarouselsecondstkaveh'],
                    'order' => 'DESC',
                    'orderby' => 'date',
                    'tax_query' => array(
                      array(
                        "taxonomy" => "product_cat",
                        "field"    => "tag_ID",
                        "terms"    => $settings['catproductsdigistylecarouselsecondstkaveh'],
                      ),
                    ),
                     
                    
                  );
                  if ("yes" === $settings['kaveh_exclude_out_of_stock']) {
                    $q_pc2_query_args['meta_query'] = array(
                        array(
                            'key' => '_stock_status',
                            'value' => 'outofstock',
                            'compare' => 'NOT IN',
                        ),
                    );
                  }

                  // The Query
                  $pc2_query = new \WP_Query($q_pc2_query_args);
                  
                  // The Loop
                  if ( $pc2_query->have_posts() ) {
                    while ( $pc2_query->have_posts() ) {
                      $pc2_query->the_post(); ?>
                    <?php 
                    global $product;
                    $product = wc_get_product();
                    $product_id = $product->get_id();
                    $product_type = $product->get_type();
                    $sale_price_dates_from = $sale_price_dates_to = '';
                    $sale_price = $product->get_sale_price();
                    $normal_price = $product->get_regular_price();
                    $pr_id = get_the_ID();
                    $stocka = $product->get_stock_status();
                    ?>
              <!-- Start Slide -->
              <div class="swiper-slide h-auto">
                <div class="product-fifteen bg-white h-100">
                  <div class="image position-relative d-flex align-items-center justify-content-center overflow-hidden">
                  <?php
                    $categories = wp_get_post_terms( $product->get_id(), 'product_cat' );
                    foreach ($categories as $category) {
                    $category_link = get_term_link( $category );
                    $category_name = $category->name;
                    
                    echo '<a href="' . esc_url( $category_link ) . '" class="category position-absolute top-0 start-0 bg-white d-flex align-items-center justify-content-center">';
                    echo  esc_html( $category_name );
                    echo '</a>';
                    }
                    ?>
                    <a href="<?php the_permalink(); ?>">
                      <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title(); ?>" width="290" height="290">
                    </a>
                    <?php if (!empty($normal_price)) {
                            if ("instock" == $stocka) {
                              if (!empty($sale_price)) { ?>
                    <span
                      class="offer position-absolute bottom-0 end-0 text-white d-flex align-items-center justify-content-center">
                      <?php if (class_exists('kavehWoo')) { $offer_percentage = kavehWoo::showofferpercentage($product); echo $offer_percentage; } ?> </span>
                      <?php }
                         } 
                     }
                     $terms = get_the_terms( $pr_id , 'pa_size' );
                     // Loop through the terms
                     if(!empty($terms)){ ?>
                    <ul class="sizes d-flex align-items-center position-absolute bottom-0 end-0 w-100 bg-white">
                    <?php
                      foreach ( $terms as $term ) {
                      $tooltip = get_term_meta( $term->term_id, 'wpcvs_tooltip', true ) ?: $term->name;
                      ?>
                      <li>
                        <a href="<?php the_permalink(); ?>" class="d-block"> <?php echo esc_attr( $tooltip ) ?> </a>
                      </li>
                      <?php
                      }
                      ?>
                    </ul>
                    <?php }else{ ?>
                      <style>
                      .product-fifteen:hover .image .offer {
                        -webkit-transform: translateY(0);
                        -moz-transform: translateY(0);
                        -ms-transform: translateY(0);
                        -o-transform: translateY(0);
                        transform: translateY(0);
                    }
                    </style>
                  <?php  } ?>
                  </div>
                  <div class="d-flex align-items-center justify-content-between">
                    <h2 class="title mb-0">
                      <a href="<?php the_permalink(); ?>"><?php the_title(); ?>  </a>
                    </h2>
                  </div>
                  <div class="price d-flex align-items-center justify-content-end">
                  <?php if("instock"==$stocka){ 
                          if ( !$product->is_type( 'variable' ) ) { 
                              if(empty($sale_price) && empty($normal_price)) { 
                                  $price_v = $product->get_price_html(); ?>
                                  <?php
                                  echo str_replace("&ndash;","<span class=\"dashvar\"> – </span>", $price_v); ?>
                                  <?php
                                  ?>
                                  <?php }else{ ?>
                                  <?php if(!empty($sale_price) ) { ?>
                                  
                                  <del class="me-2">
                                  <?php if (!empty($normal_price)) {
                                  echo number_format($normal_price, 0, '.', ',');
                                  } ?>
                                  </del>
                                  <?php echo number_format($sale_price, 0, '.', ','); ?>
                                  <span class="currency-fifteen">
                                  <?php echo get_woocommerce_currency_symbol(); ?>
                                  </span>
                                  <?php }else{ ?>
                                  <?php if (!empty($normal_price)) { ?>
                                  <?php
                                  echo number_format($normal_price, 0, '.', ',');
                                  } ?>
                                  <span class="currency-fifteen">
                                  <?php echo get_woocommerce_currency_symbol(); ?>
                                  </span>
                                  <?php } ?>
                                  <?php } }else{ 
                                  $price_v = $product->get_price_html(); ?>
                                  <?php
                                  echo str_replace("&ndash;","<span class=\"dashvar\"> – </span>", $price_v); ?>
                                  <?php
                                  } 
                                  }else{ ?>
                                    <span class="outstock">
                                    Unavailable 
                                    </span>
                                  <?php
                                  }
                                  ?>
                  </div>
                </div>
              </div>
              <!-- End Slide -->
            <?php
                // Reset Original Post Data
                  wp_reset_postdata();
                }
              }
                  
                  ?>
              <?php }elseif('all'===$settings['pproductsdigistylecarouselsecondstkaveh']){
                // WP_Query args
            $ordvalue = $settings['psortproductsdigistylecarouselsecondstkaveh'];
            $ordi = $settings['psortiproductsdigistylecarouselsecondstkaveh'];
            $q_pc2_query_args = array(
              'post_type' => array('product'),
'post_status' => array('publish'),
              'posts_per_page' => $settings['productnumberproductsdigistylecarouselsecondstkaveh'],
              'order' => $ordi,
              'orderby' => 'meta_value_num',
              'meta_key'       => $ordvalue,

             
            );
            if ("yes" === $settings['kaveh_exclude_out_of_stock']) {
              $q_pc2_query_args['meta_query'] = array(
                  array(
                      'key' => '_stock_status',
                      'value' => 'outofstock',
                      'compare' => 'NOT IN',
                  ),
              );
            }

            // The Query
            $pc2_query = new \WP_Query($q_pc2_query_args);

            // The Loop
            if ( $pc2_query->have_posts() ) {
              while ( $pc2_query->have_posts() ) {
                $pc2_query->the_post(); ?>
                <?php 
                global $product;
                $product = wc_get_product();
                $product_id = $product->get_id();
                $product_type = $product->get_type();
                $sale_price_dates_from = $sale_price_dates_to = '';
                $sale_price = $product->get_sale_price();
                $normal_price = $product->get_regular_price();
                $pr_id = get_the_ID();
                $stocka = $product->get_stock_status();
                ?>
              <!-- Start Slide -->
              <div class="swiper-slide h-auto">
                <div class="product-fifteen bg-white h-100">
                  <div class="image position-relative d-flex align-items-center justify-content-center overflow-hidden">
                  <?php
                    $categories = wp_get_post_terms( $product->get_id(), 'product_cat' );
                    foreach ($categories as $category) {
                    $category_link = get_term_link( $category );
                    $category_name = $category->name;
                    
                    echo '<a href="' . esc_url( $category_link ) . '" class="category position-absolute top-0 start-0 bg-white d-flex align-items-center justify-content-center">';
                    echo  esc_html( $category_name );
                    echo '</a>';
                    }
                    ?>
                    <a href="<?php the_permalink(); ?>">
                      <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title(); ?>" width="290" height="290">
                    </a>
                    <?php if (!empty($normal_price)) {
                            if ("instock" == $stocka) {
                              if (!empty($sale_price)) { ?>
                    <span
                      class="offer position-absolute bottom-0 end-0 text-white d-flex align-items-center justify-content-center">
                      <?php if (class_exists('kavehWoo')) { $offer_percentage = kavehWoo::showofferpercentage($product); echo $offer_percentage; } ?> </span>
                      <?php }
                         } 
                     }
                     $terms = get_the_terms( $pr_id , 'pa_size' );
                     // Loop through the terms
                     if(!empty($terms)){ ?>
                    <ul class="sizes d-flex align-items-center position-absolute bottom-0 end-0 w-100 bg-white">
                    <?php
                      foreach ( $terms as $term ) {
                      $tooltip = get_term_meta( $term->term_id, 'wpcvs_tooltip', true ) ?: $term->name;
                      ?>
                      <li>
                        <a href="<?php the_permalink(); ?>" class="d-block"> <?php echo esc_attr( $tooltip ) ?> </a>
                      </li>
                      <?php
                      }
                      ?>
                    </ul>
                    <?php }else{ ?>
                      <style>
                      .product-fifteen:hover .image .offer {
                        -webkit-transform: translateY(0);
                        -moz-transform: translateY(0);
                        -ms-transform: translateY(0);
                        -o-transform: translateY(0);
                        transform: translateY(0);
                    }
                    </style>
                  <?php  } ?>
                  </div>
                  <div class="d-flex align-items-center justify-content-between">
                    <h2 class="title mb-0">
                      <a href="<?php the_permalink(); ?>"><?php the_title(); ?>  </a>
                    </h2>
                  </div>
                  <div class="price d-flex align-items-center justify-content-end">
                  <?php if("instock"==$stocka){ 
                          if ( !$product->is_type( 'variable' ) ) { 
                              if(empty($sale_price) && empty($normal_price)) { 
                                  $price_v = $product->get_price_html(); ?>
                                  <?php
                                  echo str_replace("&ndash;","<span class=\"dashvar\"> – </span>", $price_v); ?>
                                  <?php
                                  ?>
                                  <?php }else{ ?>
                                  <?php if(!empty($sale_price) ) { ?>
                                  
                                  <del class="me-2">
                                  <?php if (!empty($normal_price)) {
                                  echo number_format($normal_price, 0, '.', ',');
                                  } ?>
                                  </del>
                                  <?php echo number_format($sale_price, 0, '.', ','); ?>
                                  <span class="currency-fifteen">
                                  <?php echo get_woocommerce_currency_symbol(); ?>
                                  </span>
                                  <?php }else{ ?>
                                  <?php if (!empty($normal_price)) { ?>
                                  <?php
                                  echo number_format($normal_price, 0, '.', ',');
                                  } ?>
                                  <span class="currency-fifteen">
                                  <?php echo get_woocommerce_currency_symbol(); ?>
                                  </span>
                                  <?php } ?>
                                  <?php } }else{ 
                                  $price_v = $product->get_price_html(); ?>
                                  <?php
                                  echo str_replace("&ndash;","<span class=\"dashvar\"> – </span>", $price_v); ?>
                                  <?php
                                  } 
                                  }else{ ?>
                                    <span class="outstock">
                                    Unavailable 
                                    </span>
                                  <?php
                                  }
                                  ?>
                  </div>
                </div>
              </div>
              <!-- End Slide -->
                <?php
                // Reset Original Post Data
                  wp_reset_postdata();
                }
              }
                  
                  ?>
                <?php } ?>            
            </div>
            <?php if('yes'===$settings['showarrowproductsdigistylecarouselsecondstkaveh']){ ?>
            <!-- Start Button -->
            <div class="swiper-button-next d-none d-md-flex align-items-md-center justify-content-md-center"></div>
            <div class="swiper-button-prev d-none d-md-flex align-items-md-center justify-content-md-center"></div>
            <!-- End Button -->
            <?php } ?>
          </div>
          <!-- End Carousel -->
        </div>
        <!-- End Products -->
        <a href="<?php echo  esc_url($settings['buttontilink2productsdigistylecarouselsecondstkaveh']); ?>" class="btn btn-outline-dark-3 btn-more mt-4 d-md-none d-block mx-auto"> <?php echo  esc_html($settings['buttonti2productsdigistylecarouselsecondstkaveh']); ?></a>
      </div>
    </section>
    <style>
.product-fifteen .image img {
    mix-blend-mode: darken;
    max-height: 200px;
    object-fit: contain;
}
.currency-fifteen{
  font-size:13px;
  margin-right:3px;
}
.product-fifteen .image {
    height: 350px;
}
.top-selling-products-digi-left .product-fifteen {
border:none;
}
    </style>
  
    <?php
  }


}
