<?php

use Elementor\Widget_Base;
use Elementor\Controls_Manager;

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


class Productsbanimodesecondstcarouselkaveh extends Widget_Base{

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

  public function get_title(){
    return esc_html__( 'Bani Mode 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(
        'contentproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Element Title', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
      $this->add_control(
        'imgbeforeproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Image Above Title', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::MEDIA,
        ]
      );
      $this->add_control(
        'imgtilink2productsbanimodesecondstcarouselkaveh',
        [
            'label' => esc_html__( 'Image Link', 'kavehTheme' ),
            'type' => \Elementor\Controls_Manager::TEXT,
            'default' => esc_html__( '#', 'kavehTheme' ),
    
        ]
    );
        $this->add_control(
          'buttonti1productsbanimodesecondstcarouselkaveh',
          [
              'label' => esc_html__( 'Title', 'kavehTheme' ),
				'type' => \Elementor\Controls_Manager::TEXT,
				'default' => esc_html__( 'Best Selling Products', 'kavehTheme' ),
      
          ]
      );
      $this->add_control(
        'tagheading1productsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Title Tag', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SELECT,
          'default' => 'span',
          '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(
        'showtimerproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Show Timer?', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SWITCHER,
          'yes' => esc_html__( 'Yes', 'kavehTheme' ),
          'no' => esc_html__( 'No', 'kavehTheme' ),
          'return_value' => 'yes',
          'default' => 'yes',
        ]
      );
      $this->add_control(
        'dateproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Group Discount Time?', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DATE_TIME,
          'condition' => [
            'showtimerproductsbanimodesecondstcarouselkaveh' => 'yes',
          ],
        ]
      );
    $this->add_control(
      'buttonti2productsbanimodesecondstcarouselkaveh',
      [
          'label' => esc_html__( 'Button Title', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::TEXT,
          'default' => esc_html__( 'View All', 'kavehTheme' ),
  
      ]
  );
  $this->add_control(
    'buttontilink2productsbanimodesecondstcarouselkaveh',
    [
        'label' => esc_html__( 'Button Link', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => esc_html__( '#', 'kavehTheme' ),

    ]
);
    $this->end_controls_section();   

      $this->start_controls_section(
        'content4productsbanimodesecondstcarouselkaveh',
        [
          '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(
    'pproductsbanimodesecondstcarouselkaveh',
    [
      '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(
      'psortproductsbanimodesecondstcarouselkaveh',
      [
        '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(
        'psortiproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Sort Type', '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(
    'catproductsbanimodesecondstcarouselkaveh',
    [
      'label' => esc_html__( 'Select Category', 'kavehTheme' ),
      'type' => \Elementor\Controls_Manager::SELECT2, 
      'multiple' => true,
      'options' => $options5,
      'condition' => [
        'pproductsbanimodesecondstcarouselkaveh' => 'cat',
      ],
    ]
);
$this->end_controls_section();   
$this->start_controls_section(
  'content5productsbanimodesecondstcarouselkaveh',
  [
    'label' => esc_html__( 'Carousel Settings', 'kavehTheme' ),
    'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
  ]
);
$this->add_control(
  'productnumberproductsbanimodesecondstcarouselkaveh',
  [
    'label' => esc_html__( 'Number of Products Displayed', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 0,
    'max' => 50,
    'step' => 1,
    'default' => 5,
  ]
);
$this->add_control(
  'productcolumnproductsbanimodesecondstcarouselkaveh',
  [
    '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(
  'productcolumn2productsbanimodesecondstcarouselkaveh',
  [
    '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(
  'productcolumn3productsbanimodesecondstcarouselkaveh',
  [
    '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(
  'autoplayproductsbanimodesecondstcarouselkaveh',
  [
    '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(
  'autoplaydelayproductsbanimodesecondstcarouselkaveh',
  [
    'label' => esc_html__( 'Autoplay Delay (milliseconds)', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 1000,
    'max' => 10000,
    'step' => 500,
    'default' => 3000,
    'condition' => [
      'autoplayproductsbanimodesecondstcarouselkaveh' => 'yes',
    ],
  ]
);
$this->add_control(
  'pauseonhoverproductsbanimodesecondstcarouselkaveh',
  [
    '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' => [
      'autoplayproductsbanimodesecondstcarouselkaveh' => 'yes',
    ],
  ]
);
// Loop settings
$this->add_control(
  'loopproductsbanimodesecondstcarouselkaveh',
  [
    '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(
  'speedproductsbanimodesecondstcarouselkaveh',
  [
    '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(
  'centeredslidesproductsbanimodesecondstcarouselkaveh',
  [
    '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(
  'freemodeproductsbanimodesecondstcarouselkaveh',
  [
    '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(
  'effectproductsbanimodesecondstcarouselkaveh',
  [
    '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(
  'showarrowproductsbanimodesecondstcarouselkaveh',
  [
    '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(
  'showdotsproductsbanimodesecondstcarouselkaveh',
  [
    '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_productsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Element Top Section Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'catimg1widthproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Image Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => [ 'px' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 500,
              'step' => 1,
            ],
          ],
          'selectors' => [
            '{{WRAPPER}} .amazing-offer-bani-heading img' => 'width: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      $this->add_control(
        'catimg1height2productsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Image Height', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => [ 'px' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 500,
              'step' => 1,
            ],
          ],
          'selectors' => [
            '{{WRAPPER}} .amazing-offer-bani-heading img' => 'height: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'buttona_productsbanimodesecondstcarouselkaveh',
          'label' => esc_html__( 'Title Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .amazing-offer-bani-heading .timear>span',
        ]
      );
      $this->add_control(
        'textabuttoncolorproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Title Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .amazing-offer-bani-heading .timear>span' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'bgtimerbuttoncolorproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Timer Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .amazing-offer-bani-heading .timear ul li' => 'background-color: {{VALUE}}',
            '{{WRAPPER}} .amazing-offer-bani-heading .timear ul' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      
      $this->add_control(
        'timerbuttoncolorproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Timer Numbers Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .amazing-offer-bani-heading .timear ul li' => 'color: {{VALUE}} !important',
          ],
        ]
      ); 
      $this->end_controls_section();
      $this->start_controls_section(
        'styleb_productsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Button Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'button_productsbanimodesecondstcarouselkaveh',
          'label' => esc_html__( 'Button Text Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .btn-more-bani',
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Text_Shadow::get_type(),
        [
          'name' => 'text_shadowproductsbanimodesecondstcarouselkaveh',
          'label' => esc_html__( 'Text Shadow', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .btn-more-bani',
        ]
      );
      $this->start_controls_tabs(
        'style_tabsproductsbanimodesecondstcarouselkaveh'
      );
    
      $this->start_controls_tab(
        'style_normal_tabproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Normal', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbuttoncolorproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Button Text Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .btn-more-bani' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttoncolorproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Button Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .btn-more-bani' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttonradiusproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Button Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .btn-more-bani' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Border::get_type(),
        [
          'name' => 'borderproductsbanimodesecondstcarouselkaveh',
          'label' => esc_html__( 'Border', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .btn-more-bani',
        ]
      );
      $this->add_control(
        'buttonbordersproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Border Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'condition' => [
            'borderproductsbanimodesecondstcarouselkaveh!' => '',
          ],
          'selectors' => [
            '{{WRAPPER}} .btn-more-bani' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->end_controls_tab();
      $this->start_controls_tab(
        'style_hove_tabproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Hover', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbuttoncolorhoverproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Button Text Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .btn-more-bani:hover' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttoncolorhoverproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Button Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .btn-more-bani:hover' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttonradiushoverproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Button Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .btn-more-bani:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Border::get_type(),
        [
          'name' => 'borderhoverproductsbanimodesecondstcarouselkaveh',
          'label' => esc_html__( 'Border', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .btn-more-bani:hover',
        ]
      );
      $this->add_control(
        'buttonbordershoverproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Border Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'condition' => [
            'borderhoverproductsbanimodesecondstcarouselkaveh!' => '',
          ],
          'selectors' => [
            '{{WRAPPER}} .btn-more-bani: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_shadowproductsbanimodesecondstcarouselkaveh',
          'label' => esc_html__( 'Button Shadow', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .btn-more-bani',
        ]
      );
      $this->add_control(
        'hr2productsbanimodesecondstcarouselkaveh',
        [
          'type' => \Elementor\Controls_Manager::DIVIDER,
        ]
      );
      $this->add_control(
        'buttonpaddingproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Padding', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .btn-more-bani' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->end_controls_section();
      $this->start_controls_section(
        'style5_productsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Carousel Arrows Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
          'condition' => [
            'showarrowproductsbanimodesecondstcarouselkaveh' => 'yes',

          ],
        ]
      );
      $this->add_control(
        'iconsizenchbproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Icon Size', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => [ 'px' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 200,
              'step' => 1,
            ],
          ],
          'selectors' => [
            '{{WRAPPER}} .swiper-bani .swiper-button-next::after' => 'font-size: {{SIZE}}{{UNIT}};',
            '{{WRAPPER}} .swiper-bani .swiper-button-prev::after' => 'font-size: {{SIZE}}{{UNIT}};',

          ],
        ]
      );
      $this->start_controls_tabs(
        'style_tabsarrowproductsbanimodesecondstcarouselkaveh'
      );
    
      $this->start_controls_tab(
        'style_normal_tabarrowproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Normal', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbutton1colorarrowproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Icon Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .swiper-bani .swiper-button-next::after' => 'color: {{VALUE}}',
            '{{WRAPPER}} .swiper-bani .swiper-button-prev::after' => 'color: {{VALUE}}',

          ],
        ]
      ); 
      $this->end_controls_tab();
      $this->start_controls_tab(
        'style_hove_tabarrowproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Hover', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbutton1hovercolorarrowproductsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Icon Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .swiper-bani .swiper-button-next:hover::after' => 'color: {{VALUE}}',
            '{{WRAPPER}} .swiper-bani .swiper-button-prev:hover::after' => 'color: {{VALUE}}',
           ],
        ]
      ); 
      $this->end_controls_tab();
      $this->end_controls_tabs();
      $this->end_controls_section();
      $this->start_controls_section(
        'stylebox_2productsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Product Box Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'boxbghov2productsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Product Image Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .product-seventeen .image>a::before' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'boxradi2productsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Product Image Background Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .product-seventeen .image>a::before' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->add_control(
        'boxpercentage2productsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Discount Percentage Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .product-seventeen .image .offer' => 'background-color: {{VALUE}}',

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

          ],
        ]
      ); 
      $this->add_control(
        'gallery2productsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Gallery Image Count Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .product-seventeen .image .colors li.count' => 'color: {{VALUE}} !important',

          ],
        ]
      ); 
      $this->add_control(
        'pricecle2productsbanimodesecondstcarouselkaveh',
        [
          'label' => esc_html__( 'Price Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .product-seventeen .price' => 'color: {{VALUE}} !important',
            '{{WRAPPER}} span.woocommerce-Price-amount.amount' => '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['productcolumn3productsbanimodesecondstcarouselkaveh'],
          'spaceBetween' => 12
        ),
        576 => array(
          'slidesPerView' => (int) $settings['productcolumn2productsbanimodesecondstcarouselkaveh'],
          'spaceBetween' => 12
        ),
        768 => array(
          'slidesPerView' => (int) $settings['productcolumn2productsbanimodesecondstcarouselkaveh'],
          'spaceBetween' => 20
        ),
        992 => array(
          'slidesPerView' => (int) $settings['productcolumnproductsbanimodesecondstcarouselkaveh'],
          'spaceBetween' => 20
        ),
        1200 => array(
          'slidesPerView' => (int) $settings['productcolumnproductsbanimodesecondstcarouselkaveh'],
          'spaceBetween' => 24
        )
      )
    );
    // Add navigation if arrows are enabled
    if (isset($settings['showarrowproductsbanimodesecondstcarouselkaveh']) && $settings['showarrowproductsbanimodesecondstcarouselkaveh'] === '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['loopproductsbanimodesecondstcarouselkaveh']) && $settings['loopproductsbanimodesecondstcarouselkaveh'] === 'yes') {
      $swiper_settings['loop'] = true;
    }
    if (isset($settings['speedproductsbanimodesecondstcarouselkaveh']) && !empty($settings['speedproductsbanimodesecondstcarouselkaveh'])) {
      $swiper_settings['speed'] = (int) $settings['speedproductsbanimodesecondstcarouselkaveh'];
    }
    if (isset($settings['centeredslidesproductsbanimodesecondstcarouselkaveh']) && $settings['centeredslidesproductsbanimodesecondstcarouselkaveh'] === 'yes') {
      $swiper_settings['centeredSlides'] = true;
    }
    if (isset($settings['freemodeproductsbanimodesecondstcarouselkaveh']) && $settings['freemodeproductsbanimodesecondstcarouselkaveh'] === 'yes') {
      $swiper_settings['freeMode'] = true;
    }
    if (isset($settings['effectproductsbanimodesecondstcarouselkaveh']) && $settings['effectproductsbanimodesecondstcarouselkaveh'] !== 'slide') {
      $swiper_settings['effect'] = $settings['effectproductsbanimodesecondstcarouselkaveh'];
    }
    // Add autoplay if enabled
    if (isset($settings['autoplayproductsbanimodesecondstcarouselkaveh']) && $settings['autoplayproductsbanimodesecondstcarouselkaveh'] === 'yes') {
      $autoplay_settings = array(
        'delay' => isset($settings['autoplaydelayproductsbanimodesecondstcarouselkaveh']) ? (int) $settings['autoplaydelayproductsbanimodesecondstcarouselkaveh'] : 3000,
        'disableOnInteraction' => false
      );
      if (isset($settings['pauseonhoverproductsbanimodesecondstcarouselkaveh']) && $settings['pauseonhoverproductsbanimodesecondstcarouselkaveh'] === 'yes') {
        $autoplay_settings['pauseOnMouseEnter'] = true;
      }
      $swiper_settings['autoplay'] = $autoplay_settings;
    }
    // Add pagination if enabled
    if (isset($settings['showdotsproductsbanimodesecondstcarouselkaveh']) && $settings['showdotsproductsbanimodesecondstcarouselkaveh'] === '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="amazing-offer-bani">
      <div class="container">
        <!-- Start Heading -->
        <div class="amazing-offer-bani-heading d-flex align-items-center justify-content-between mb-3">
          <a href="<?php echo  esc_url($settings['imgtilink2productsbanimodesecondstcarouselkaveh']); ?>">
            <img src="<?php echo esc_url($settings['imgbeforeproductsbanimodesecondstcarouselkaveh']['url']); ?>" alt="" width="306" height="57"
              class="d-block">
          </a>
          <div class="timear d-flex align-items-center">
            <<?php echo  esc_attr($settings['tagheading1productsbanimodesecondstcarouselkaveh']); ?> class="fw-semibold d-none d-md-block"> <?php echo esc_html($settings['buttonti1productsbanimodesecondstcarouselkaveh']); ?></<?php echo  esc_attr($settings['tagheading1productsbanimodesecondstcarouselkaveh']); ?>>
            <?php $deal_end_date = $settings['dateproductsbanimodesecondstcarouselkaveh']; ?>
            <?php if (!empty($deal_end_date)){ ?>
            <ul class="d-flex align-items-center fs-4 fw-bold" data-time="<?php  echo $deal_end_date; ?>">
              <li class="second d-flex align-items-center justify-content-center text-white fw-bold rounded-3 fs-4">00
              </li>:
              <li class="minute d-flex align-items-center justify-content-center text-white fw-bold rounded-3 fs-4">00
              </li>:
              <li class="hour d-flex align-items-center justify-content-center text-white fw-bold rounded-3 fs-4">00
              </li>:
              <li class="day d-flex align-items-center justify-content-center text-white fw-bold rounded-3 fs-4">00
            </li>
            </ul>
            <?php }else{}
            ?>
          </div>
        </div>
        <!-- End Heading -->
        <div class="position-relative">
          <!-- Start Carousel -->
          <div class="swiper swiper-top-selling-products-bani overflow-hidden swiper-bani"  data-swiper='<?php echo $swiper_json; ?>'>
            <div class="swiper-wrapper">
            <?php if('cat'===$settings['pproductsbanimodesecondstcarouselkaveh']){ ?>
              <?php 
                  
                  // WP_Query args
                  $q_pc2_query_args = array(
                    'post_type' => array('product'),
'post_status' => array('publish'),
                    'posts_per_page' => $settings['productnumberproductsbanimodesecondstcarouselkaveh'],
                    'order' => 'DESC',
                    'orderby' => 'date',
                    'tax_query' => array(
                      array(
                        "taxonomy" => "product_cat",
                        "field"    => "tag_ID",
                        "terms"    => $settings['catproductsbanimodesecondstcarouselkaveh'],
                      ),
                    ),
                     
                    
                  );
                  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">
              <div <?php wc_product_class( 'product-seventeen pr' . $pr_id, $product ); ?>>
               <div class="image position-relative overflow-hidden rounded-3 align-items-center">
                    <a href="<?php the_permalink(); ?>" class="d-block">
                    <?php 
                    $attachment_ids = $product->get_gallery_image_ids();
                    ?>
                      <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title(); ?>" width="330" height="396"
                        class="w-100 d-block">
                        <?php if(!empty($attachment_ids)){ 
                         $imurl = wp_get_attachment_url($attachment_ids[0])
                          ?>
                      <img src="<?php echo $imurl; ?>" alt="<?php the_title(); ?>" width="330" height="396"
                        class="position-absolute top-0 end-0 w-100 h-100">
                        <?php }else{ ?>
                          <style>
                            <?php echo '.pr'.$pr_id ?>.product-seventeen .image>a img:last-child {
                            opacity: 1 !important;
                            visibility: visible !important;
                            }
                            <?php echo '.pr'.$pr_id ?>.product-seventeen:hover .image>a img:first-child {
                            opacity: 1 !important;
                            visibility: visible !important;
                            }
                          </style>
                          <?php } ?>
                    </a>
                    <?php if (!empty($normal_price)) {
                            if ("instock" == $stocka) {
                              if (!empty($sale_price)) { ?>
                    <span
                      class="offer position-absolute end-0 d-flex align-items-center justify-content-center fw-bold text-white">
                      <?php if (class_exists('kavehWoo')) { $offer_percentage = kavehWoo::showofferpercentage($product); echo $offer_percentage; } ?> </span>
                      <?php }
                         } 
                     } ?>
                    <ul class="icons position-absolute">
                                                                               <?php if($this->options['kaveh_wishlist_system'] === '1'): ?>   

                      <li class="d-flex align-items-center justify-content-center rounded-circle bg-white">
        <?php echo do_shortcode( '[wlm_button]' ); ?>                
                          </li>
                                                  <?php endif; ?>

                      <li class="d-flex align-items-center justify-content-center rounded-circle bg-white" type="button" id="eyeid" data-bs-toggle="modal" data-bs-target="#modal-product">
                      <i class="isax isax-eye3"></i>
                      </li>
                    </ul>

                    <?php
                    $attachment_ids = $product->get_gallery_image_ids();
                  $image_count = count($attachment_ids);

                  // Start the ul element
                  echo '<ul class="colors d-flex justify-content-center w-100 px-2 end-0 position-absolute">';

                  // Check the number of images
                  if ($image_count <= 5) {
                      // Loop through each attachment ID
                      foreach ($attachment_ids as $attachment_id) {
                          // Get the image URL
                          $image_url = wp_get_attachment_url($attachment_id);
                          // Output the li element for each image
                          echo '<li class="bg-white overflow-hidden">';
                          echo '<a href="javascript:void(0)" class="d-flex align-items-center justify-content-center">';
                          echo '<img src="' . esc_url($image_url) . '" alt="product name" width="43" height="45" class="d-block w-100 h-100">';
                          echo '</a></li>';
                      }
                  } else {
                      // If there are more than 5 images, display the first 5
                      for ($i = 0; $i < 5; $i++) {
                          $image_url = wp_get_attachment_url($attachment_ids[$i]);
                          echo '<li class="bg-white overflow-hidden">';
                          echo '<a href="javascript:void(0)" class="d-flex align-items-center justify-content-center">';
                          echo '<img src="' . esc_url($image_url) . '" alt="product name" width="43" height="45" class="d-block w-100 h-100">';
                          echo '</a></li>';
                      }
                      // Then, display the count of additional images
                      $additional_count = $image_count - 5;
                      echo '<li class="count d-flex align-items-center justify-content-center bg-white fs-6"> +' . esc_html($additional_count) . ' </li>';
                  }

                  // Close the ul element
                  echo '</ul>';
                  ?>
                  </div>

                  <div class="brand-last-price d-flex align-items-center justify-content-between mt-3">
                    <?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="brand fw-semibold text-truncate">';
                    echo  esc_html( $category_name );
                    echo '</a>';
                    }
                    ?>
                    
                    <?php if("instock"==$stocka){ 
                          if ( !$product->is_type( 'variable' ) ) { 
                              if(!empty($sale_price) && empty(!$normal_price)) { ?>
                    <del class="last-price ms-2 text-nowrap"> <?php  echo number_format($normal_price, 0, '.', ',');  ?> <?php echo get_woocommerce_currency_symbol(); ?> </del>
                    <?php }
                    }
                   } ?>
                  </div>
                  <div class="title-price d-flex align-items-center justify-content-between my-3">
                    <h2 class="title mb-0 fw-normal w-100">
                      <a href="<?php the_permalink(); ?>" class="d-block text-truncate"> <?php the_title(); ?>
                      </a>
                    </h2>
                    <div class="price ms-2 text-nowrap">
                    <?php if("instock"==$stocka){ 
                       if ( !$product->is_type( 'variable' ) ) { 
                              if(!empty($sale_price) && !empty($normal_price)) { ?>
                              <?php echo number_format($sale_price, 0, '.', ','); ?> <?php echo get_woocommerce_currency_symbol(); ?>
                         <?php }elseif(!empty($normal_price)){
                         if (!empty($normal_price)) { ?>
                          <div class="price ms-2 text-nowrap">
                          <?php echo number_format((float)$sale_price, 0, '.', ','); ?> <?php echo get_woocommerce_currency_symbol(); ?>
                          </div>
                          <?php }
                         }else{          
                      $price_v = $product->get_price_html(); ?>
                     <?php echo str_replace("&ndash;","<span class=\"dashvar\"> – </span>", $price_v); ?>
                     <?php
                    }
                       }else{          
                        $price_v = $product->get_price_html(); ?>
                      <div class="price ms-2 text-nowrap">
                       <?php echo str_replace("&ndash;","<span class=\"dashvar\"> – </span>", $price_v); ?>
                       </div>
                       <?php
                      }
                      }else{ ?>
                        <span class="outstock">
                        <?php echo esc_html__( 'Out of Stock', 'kavehTheme' ); ?>
                        </span>
                      <?php
                      }
                      ?>  
                    </div>
                  </div>

                  <?php       
                  $terms = get_the_terms( $pr_id , 'pa_size' );
                  $max_display = 3; // Maximum number of sizes to display
                  // Check if there are any terms and more than the maximum display limit
                  if(!empty($terms) && !is_wp_error($terms) && count($terms) > $max_display){ ?>
                      <ul class="sizes d-flex align-items-center">
                      <?php
                      $displayed = 0; // Counter for displayed sizes
                      foreach ( $terms as $term ) {
                          // Stop the loop if maximum display limit is reached
                          if($displayed >= $max_display) break;
                          
                          $tooltip = get_term_meta( $term->term_id, 'wpcvs_tooltip', true ) ?: $term->name;
                          ?>
                          <li>
                              <a href="<?php the_permalink(); ?>" class="d-flex align-items-center justify-content-center"> <?php echo esc_attr( $tooltip ); ?> </a>
                          </li>
                          <?php
                          $displayed++;
                      }
                      // Calculate remaining sizes
                      $remaining = count($terms) - $max_display;
                      ?>
                      <li>
                          <a href="<?php the_permalink(); ?>" class="d-flex align-items-center justify-content-center more"> +<?php echo $remaining; ?> </a>
                      </li>
                      </ul>
                  <?php 
                  } elseif(!empty($terms)) { // If there are terms but 3 or less
                      ?>
                      <ul class="sizes d-flex align-items-center">
                      <?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-flex align-items-center justify-content-center"> <?php echo esc_attr( $tooltip ); ?> </a>
                          </li>
                          <?php
                      }
                      ?>
                      </ul>
                  <?php } ?>

                </div>
              </div>
              <!-- End Slide -->
            <?php
                // Reset Original Post Data
                  wp_reset_postdata();
                }
              }
                  
                  ?>
              <?php }elseif('all'===$settings['pproductsbanimodesecondstcarouselkaveh']){
                // WP_Query args
            $ordvalue = $settings['psortproductsbanimodesecondstcarouselkaveh'];
            $ordi = $settings['psortiproductsbanimodesecondstcarouselkaveh'];
            $q_pc2_query_args = array(
              'post_type' => array('product'),
'post_status' => array('publish'),
              'posts_per_page' => $settings['productnumberproductsbanimodesecondstcarouselkaveh'],
              '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">
              <div <?php wc_product_class( 'product-seventeen pr' . $pr_id, $product ); ?>>
               <div class="image position-relative overflow-hidden rounded-3 align-items-center">
                    <a href="<?php the_permalink(); ?>" class="d-block">
                    <?php 
                    $attachment_ids = $product->get_gallery_image_ids();
                    ?>
                      <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title(); ?>" width="330" height="396"
                        class="w-100 d-block">
                        <?php if(!empty($attachment_ids)){ 
                         $imurl = wp_get_attachment_url($attachment_ids[0])
                          ?>
                      <img src="<?php echo $imurl; ?>" alt="<?php the_title(); ?>" width="330" height="396"
                        class="position-absolute top-0 end-0 w-100 h-100">
                        <?php }else{ ?>
                          <style>
                            <?php echo '.pr'.$pr_id ?>.product-seventeen .image>a img:last-child {
                            opacity: 1 !important;
                            visibility: visible !important;
                            }
                            <?php echo '.pr'.$pr_id ?>.product-seventeen:hover .image>a img:first-child {
                            opacity: 1 !important;
                            visibility: visible !important;
                            }
                          </style>
                          <?php } ?>
                    </a>
                    <?php if (!empty($normal_price)) {
                            if ("instock" == $stocka) {
                              if (!empty($sale_price)) { ?>
                    <span
                      class="offer position-absolute end-0 d-flex align-items-center justify-content-center fw-bold text-white">
                      <?php if (class_exists('kavehWoo')) { $offer_percentage = kavehWoo::showofferpercentage($product); echo $offer_percentage; } ?> </span>
                      <?php }
                         } 
                     } ?>
                    <ul class="icons position-absolute">
                                                                               <?php if($this->options['kaveh_wishlist_system'] === '1'): ?>   

                      <li class="d-flex align-items-center justify-content-center rounded-circle bg-white">
        <?php echo do_shortcode( '[wlm_button]' ); ?>                
                          </li>
                                                  <?php endif; ?>

                      <li class="d-flex align-items-center justify-content-center rounded-circle bg-white" type="button" id="eyeid" data-bs-toggle="modal" data-bs-target="#modal-product">
                      <i class="isax isax-eye3"></i>
                      </li>
                    </ul>

                    <?php
                    $attachment_ids = $product->get_gallery_image_ids();
                  $image_count = count($attachment_ids);

                  // Start the ul element
                  echo '<ul class="colors d-flex justify-content-center w-100 px-2 end-0 position-absolute">';

                  // Check the number of images
                  if ($image_count <= 5) {
                      // Loop through each attachment ID
                      foreach ($attachment_ids as $attachment_id) {
                          // Get the image URL
                          $image_url = wp_get_attachment_url($attachment_id);
                          // Output the li element for each image
                          echo '<li class="bg-white overflow-hidden">';
                          echo '<a href="javascript:void(0)" class="d-flex align-items-center justify-content-center">';
                          echo '<img src="' . esc_url($image_url) . '" alt="product name" width="43" height="45" class="d-block w-100 h-100">';
                          echo '</a></li>';
                      }
                  } else {
                      // If there are more than 5 images, display the first 5
                      for ($i = 0; $i < 5; $i++) {
                          $image_url = wp_get_attachment_url($attachment_ids[$i]);
                          echo '<li class="bg-white overflow-hidden">';
                          echo '<a href="javascript:void(0)" class="d-flex align-items-center justify-content-center">';
                          echo '<img src="' . esc_url($image_url) . '" alt="product name" width="43" height="45" class="d-block w-100 h-100">';
                          echo '</a></li>';
                      }
                      // Then, display the count of additional images
                      $additional_count = $image_count - 5;
                      echo '<li class="count d-flex align-items-center justify-content-center bg-white fs-6"> +' . esc_html($additional_count) . ' </li>';
                  }

                  // Close the ul element
                  echo '</ul>';
                  ?>
                  </div>

                  <div class="brand-last-price d-flex align-items-center justify-content-between mt-3">
                    <?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="brand fw-semibold text-truncate">';
                    echo  esc_html( $category_name );
                    echo '</a>';
                    }
                    ?>
                    
                    <?php if("instock"==$stocka){ 
                          if ( !$product->is_type( 'variable' ) ) { 
                              if(!empty($sale_price) && empty(!$normal_price)) { ?>
                    <del class="last-price ms-2 text-nowrap"> <?php  echo number_format($normal_price, 0, '.', ',');  ?> <?php echo get_woocommerce_currency_symbol(); ?> </del>
                    <?php }
                    }
                   } ?>
                  </div>
                  <div class="title-price d-flex align-items-center justify-content-between my-3">
                    <h2 class="title mb-0 fw-normal w-100">
                      <a href="<?php the_permalink(); ?>" class="d-block text-truncate"> <?php the_title(); ?>
                      </a>
                    </h2>
                    <div class="price ms-2 text-nowrap">
                    <?php if("instock"==$stocka){ 
                       if ( !$product->is_type( 'variable' ) ) { 
                              if(!empty($sale_price) && !empty($normal_price)) { ?>
                              <?php echo number_format($sale_price, 0, '.', ','); ?> <?php echo get_woocommerce_currency_symbol(); ?>
                         <?php }elseif(!empty($normal_price)){
                         if (!empty($normal_price)) { ?>
                          <div class="price ms-2 text-nowrap">
                          <?php echo number_format((float)$sale_price, 0, '.', ','); ?> <?php echo get_woocommerce_currency_symbol(); ?>
                          </div>
                          <?php }
                         }else{          
                      $price_v = $product->get_price_html(); ?>
                     <?php echo str_replace("&ndash;","<span class=\"dashvar\"> – </span>", $price_v); ?>
                     <?php
                    }
                       }else{          
                        $price_v = $product->get_price_html(); ?>
                      <div class="price ms-2 text-nowrap">
                       <?php echo str_replace("&ndash;","<span class=\"dashvar\"> – </span>", $price_v); ?>
                       </div>
                       <?php
                      }
                      }else{ ?>
                        <span class="outstock">
                        <?php echo esc_html__( 'Out of Stock', 'kavehTheme' ); ?>
                        </span>
                      <?php
                      }
                      ?>  
                    </div>
                  </div>

                  <?php       
                  $terms = get_the_terms( $pr_id , 'pa_size' );
                  $max_display = 3; // Maximum number of sizes to display
                  // Check if there are any terms and more than the maximum display limit
                  if(!empty($terms) && !is_wp_error($terms) && count($terms) > $max_display){ ?>
                      <ul class="sizes d-flex align-items-center">
                      <?php
                      $displayed = 0; // Counter for displayed sizes
                      foreach ( $terms as $term ) {
                          // Stop the loop if maximum display limit is reached
                          if($displayed >= $max_display) break;
                          
                          $tooltip = get_term_meta( $term->term_id, 'wpcvs_tooltip', true ) ?: $term->name;
                          ?>
                          <li>
                              <a href="<?php the_permalink(); ?>" class="d-flex align-items-center justify-content-center"> <?php echo esc_attr( $tooltip ); ?> </a>
                          </li>
                          <?php
                          $displayed++;
                      }
                      // Calculate remaining sizes
                      $remaining = count($terms) - $max_display;
                      ?>
                      <li>
                          <a href="<?php the_permalink(); ?>" class="d-flex align-items-center justify-content-center more"> +<?php echo $remaining; ?> </a>
                      </li>
                      </ul>
                  <?php 
                  } elseif(!empty($terms)) { // If there are terms but 3 or less
                      ?>
                      <ul class="sizes d-flex align-items-center">
                      <?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-flex align-items-center justify-content-center"> <?php echo esc_attr( $tooltip ); ?> </a>
                          </li>
                          <?php
                      }
                      ?>
                      </ul>
                  <?php } ?>

                </div>
              </div>
              <!-- End Slide -->
                <?php
                // Reset Original Post Data
                  wp_reset_postdata();
                }
              }
                  
                  ?>
                <?php } ?>   
            </div>
            <?php if('yes'===$settings['showarrowproductsbanimodesecondstcarouselkaveh']){ ?>
            <!-- Start Button -->
            <div class="swiper-button-next end-0 d-none d-sm-flex"></div>
            <div class="swiper-button-prev start-0 d-none d-sm-flex"></div>
            <!-- End Button -->
            <?php } ?>
          </div>
          <!-- End Carousel -->
        </div>
        <a href="<?php echo  esc_url($settings['buttontilink2productsbanimodesecondstcarouselkaveh']); ?>"
          class="btn btn-outline-dark-4 btn-more-bani d-flex align-items-center justify-content-center mx-auto w-100 mt-5 rounded-pill">
          <?php echo  esc_html($settings['buttonti2productsbanimodesecondstcarouselkaveh']); ?></a>
      </div>
    </section>
   <style>
    .product-seventeen.product {
    background-color: unset;
    -webkit-box-shadow: unset;
    -moz-box-shadow: unset;
    box-shadow: unset;
}
.product-seventeen .image {
    height: 370px;
    padding-top: 40px;
}
.product-seventeen .image>a img {
    object-fit: contain;
    max-height: 255px;
}
.product-seventeen .image>a img:last-child {
  object-fit: contain;
    max-height: 255px;
}
.product-seventeen .image>a img:last-child {
    object-fit: contain;
    max-height: 255px;
    margin-top: 40px;
}
   </style>

    <?php
  }


}
