<?php



use Elementor\Widget_Base;
use Elementor\Controls_Manager;

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


class Brandscarouselsecondstkaveh extends Widget_Base{

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

  public function get_title(){
    return esc_html__( 'Brands 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(
        'contentbrandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Element Content', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
        $this->add_control(
          'titlebrandscarouselsecondstkaveh',
          [
              'label' => esc_html__( 'Title', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => esc_html__( 'Brands', 'kavehTheme' ),
              'condition' => [
                'stylebrandscarouselsecondstkaveh' => 'two',
              ],
      
          ]
      );
      $repeater = new \Elementor\Repeater();

      $repeater->add_control(
        'brandlogobrandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Brand Image', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::MEDIA,
        ]
        );
        $repeater->add_control(
          'linkbrandscarouselsecondstkaveh',
          [
              'label' => esc_html__( 'Brand Link', 'kavehTheme' ),
              'type' => \Elementor\Controls_Manager::TEXT,
              'default' => esc_html__( '#', 'kavehTheme' ),
      
          ]
      );
    $this->add_control(
      'listbrandscarouselsecondstkaveh',
      [
        'label' => esc_html__( 'Categories', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::REPEATER,
        'fields' => $repeater->get_controls(),
        'default' => [
          [
            'linkbrandscarouselsecondstkaveh' => esc_html__( '#', 'kavehTheme' ),
          ],
      ]
      ]
    
    );
       $this->end_controls_section();
       $this->start_controls_section(
        'content2brandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Carousel Settings', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
      $this->add_control(
        'productcolumnbrandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Number of Product Columns on Desktop', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 0,
          'max' => 8,
          'step' => 0.5,
          'default' => 5,
      
        ]
      ); 
      $this->add_control(
        'productcolumn2brandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Number of Product Columns on Tablet', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 0,
          'max' => 5,
          'step' => 0.5,
          'default' => 3,
      
        ]
      );
      $this->add_control(
        'productcolumn3brandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Number of Product Columns on Mobile', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 0,
          'max' => 5,
          'step' => 0.5,
          'default' => 2.5,
      
        ]
      );
      $this->add_control(
        'autoplaybrandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Enable Autoplay', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::SELECT,
        'options' => [
          'yes' => esc_html__( 'Yes', 'kavehTheme' ),
          'no' => esc_html__( 'No', 'kavehTheme' ),
          'return_value' => 'yes',
          'default' => 'no',
        ]
        ]
      );
      $this->add_control(
        'autoplaydelaybrandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Autoplay Delay (milliseconds)', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 1000,
          'max' => 10000,
          'step' => 500,
          'default' => 3000,
          'condition' => [
            'autoplaybrandscarouselsecondstkaveh' => 'yes',
          ],
        ]
      );
      $this->add_control(
        'pauseonhoverbrandscarouselsecondstkaveh',
        [
          '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' => [
            'autoplaybrandscarouselsecondstkaveh' => 'yes',
          ],
        ]
      );
      $this->add_control(
        'loopbrandscarouselsecondstkaveh',
        [
          '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',
        ]
      );
      $this->add_control(
        'speedbrandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Transition Speed (milliseconds)', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 300,
          'max' => 3000,
          'step' => 100,
          'default' => 300,
        ]
      );
      $this->add_control(
        'centeredslidesbrandscarouselsecondstkaveh',
        [
          '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',
        ]
      );
      $this->add_control(
        'freemodebrandscarouselsecondstkaveh',
        [
          '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' ),
        ]
      );
      $this->add_control(
        'effectbrandscarouselsecondstkaveh',
        [
          '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' ),
          ],
        ]
      );
      $this->add_control(
        'showarrowbrandscarouselsecondstkaveh',
        [
          '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',
        ]
      );
      $this->add_control(
        'showdotsbrandscarouselsecondstkaveh',
        [
          '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(
        'style_brandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Box Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'buttonradiusbrandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Box Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .brands-four .brands-wrapper::before' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
            '{{WRAPPER}} .brands-four .brands-wrapper::after' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',

          ],
        ]
      );
      $this->add_control(
        'colorbrandsbgcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Border Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .brands-four .brands-wrapper::before' => 'background-color: {{VALUE}}',
          ],
        ]
      );
      $this->end_controls_section();
      $this->start_controls_section(
        'style2_brandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Brands Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'widthbrandscarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Brand Image Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => [ 'px', '%' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 2000,
              'step' => 5,
            ],
            '%' => [
              'min' => 0,
              'max' => 100,
            ],
          ],
          'selectors' => [
            '{{WRAPPER}} .brands-four .brands-item img' => 'width: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      $this->end_controls_section();

        }


  protected function render(){
    $settings = $this->get_settings_for_display();
    $clsid = $this->get_id();
    ?>
    <div class="brands brands-four">
      <div class="container">
        <div class="brands-wrapper position-relative">
          <div class="swiper swiper-brands overflow-hidden" data-swiper='<?php echo json_encode([
            "loop" => $settings['loopbrandscarouselsecondstkaveh'] === "yes",
            "autoplay" => $settings['autoplaybrandscarouselsecondstkaveh'] === "yes" ? [
              "delay" => intval($settings['autoplaydelaybrandscarouselsecondstkaveh']),
              "pauseOnMouseEnter" => $settings['pauseonhoverbrandscarouselsecondstkaveh'] === "yes"
            ] : false,
            "speed" => intval($settings['speedbrandscarouselsecondstkaveh']),
            "effect" => $settings['effectbrandscarouselsecondstkaveh'],
            "centeredSlides" => $settings['centeredslidesbrandscarouselsecondstkaveh'] === "yes",
            "freeMode" => $settings['freemodebrandscarouselsecondstkaveh'] === "yes",
            "navigation" => $settings['showarrowbrandscarouselsecondstkaveh'] === "yes" ? [
              "prevEl" => ".swiper-button-prev",
              "nextEl" => ".swiper-button-next"
            ] : false,
            "pagination" => $settings['showdotsbrandscarouselsecondstkaveh'] === "yes" ? [
              "el" => ".swiper-pagination",
              "clickable" => true
            ] : false,
            "breakpoints" => [
              320 => ["slidesPerView" => intval($settings['productcolumn3brandscarouselsecondstkaveh']), "spaceBetween" => 4],
              576 => ["slidesPerView" => intval($settings['productcolumn2brandscarouselsecondstkaveh']), "spaceBetween" => 8],
              768 => ["slidesPerView" => intval($settings['productcolumn2brandscarouselsecondstkaveh']), "spaceBetween" => 12],
              992 => ["slidesPerView" => intval($settings['productcolumnbrandscarouselsecondstkaveh']), "spaceBetween" => 12],
            ]
          ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>'>
            <div class="swiper-wrapper">
            <?php
                if ( $settings['listbrandscarouselsecondstkaveh'] ) {
                foreach (  $settings['listbrandscarouselsecondstkaveh'] as $item ) {
                ?>
              <div class="swiper-slide">
                <a href="<?php echo  esc_html($item['linkbrandscarouselsecondstkaveh']); ?>" class="brands-item d-block">
                  <img src="<?php echo esc_url($item['brandlogobrandscarouselsecondstkaveh']['url']); ?>" alt="<?php echo esc_attr(\Elementor\Control_Media::get_image_alt( $item['brandlogobrandscarouselsecondstkaveh'] )); ?>" />
                </a>
              </div>
              <?php 
            }
            }
            ?>
            </div>
            <?php if($settings['showarrowbrandscarouselsecondstkaveh'] === 'yes'){ ?>
              <div class="swiper-button-prev"></div>
              <div class="swiper-button-next"></div>
            <?php } ?>
            <?php if($settings['showdotsbrandscarouselsecondstkaveh'] === 'yes'){ ?>
              <div class="swiper-pagination"></div>
            <?php } ?>
          </div>
        </div>
      </div>
    </div>
    
    <?php
    if(empty($settings['borderbrandscarouselsecondstkaveh'])){ ?>
 <style>
  <?php echo '.elementor-element-' . $clsid . ''; ?> .brands-wrapper{
    border-width:0 !important;
  }
 </style>
    <?php
        }
        ?>
    <?php
  }


}
