<?php



use Elementor\Widget_Base;
use Elementor\Controls_Manager;

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


class Brandsfourthstkaveh extends Widget_Base{

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

  public function get_title(){
    return esc_html__( 'Brands Carousel Style Four', 'kavehTheme' );
  }

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

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

  protected function register_controls(){
    
    $this->start_controls_section(
        'contentbrandsfourthstkaveh',
        [
          'label' => esc_html__( 'Element Content', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );

      $repeater = new \Elementor\Repeater();
      $repeater->add_control(
        'img1categorycarouselkaveh',
        [
          'label' => esc_html__( 'Brand Logo', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::MEDIA,
          'default' => [
            'url' => \Elementor\Utils::get_placeholder_image_src(),
          ],
        ]
      );
      $repeater->add_control(
      'title1brandsfourthstkaveh',
      [
        'label' => esc_html__( 'Title', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => 'iPhone Products',

      ]
    );
    $repeater->add_control(
      'tagheading1brandsfourthstkaveh',
      [
        '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' ),
        ],
      ]
    );
    $repeater->add_control(
      'buttonicobrandsfourthstkaveh',
      [
        'label' => esc_html__( 'Icon', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::ICONS,
        'skin' => 'inline',
        'exclude_inline_options' => [ 'svg' ],
        'default' => [
          'value' => 'icon-arrow-left-2',
        ],
      ]
    ); 
    $repeater->add_control(
      'linkbrandsfourthstkaveh',
      [
        'label' => esc_html__( 'Link', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => '#',
      ]
    );
    $this->add_control(
      'listbrandsfourthstkaveh',
      [
        'label' => esc_html__( 'Brands', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::REPEATER,
        'fields' => $repeater->get_controls(),
        'default' => [
          [
            'title1brandsfourthstkaveh' => esc_html__( 'Title', 'kavehTheme' ),
            'linkbrandsfourthstkaveh' => esc_html__( '#', 'kavehTheme' ),
          ],
      ]
      ]
    
    );

    
       $this->end_controls_section();
       $this->start_controls_section(
        'content3brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Carousel Settings', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
      $this->add_control(
        'productcolumnbrandsfourthstkaveh',
        [
          'label' => esc_html__( 'Number of Brand Columns on Desktop', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 0,
          'max' => 8,
          'step' => 1,
          'default' => 4,
      
        ]
      );
      $this->add_control(
        'productcolumn2brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Number of Brand Columns on Tablet', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 0,
          'max' => 5,
          'step' => 1,
          'default' => 3,
      
        ]
      );
      $this->add_control(
        'productcolumn3brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Number of Brand Columns on Mobile', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 0,
          'max' => 5,
          'step' => 1,
          'default' => 1,
      
        ]
      );
      $this->add_control(
        'autoplaybrandsfourthstkaveh',
        [
          '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(
        'autoplaydelaybrandsfourthstkaveh',
        [
          'label' => esc_html__( 'Autoplay Delay (milliseconds)', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 1000,
          'max' => 10000,
          'step' => 500,
          'default' => 3000,
          'condition' => [
            'autoplaybrandsfourthstkaveh' => 'yes',
          ],
        ]
      );
      $this->add_control(
        'pauseonhoverbrandsfourthstkaveh',
        [
          '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' => [
            'autoplaybrandsfourthstkaveh' => 'yes',
          ],
        ]
      );
      $this->add_control(
        'loopbrandsfourthstkaveh',
        [
          '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(
        'speedbrandsfourthstkaveh',
        [
          'label' => esc_html__( 'Transition Speed (milliseconds)', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 300,
          'max' => 3000,
          'step' => 100,
          'default' => 300,
        ]
      );
      $this->add_control(
        'centeredslidesbrandsfourthstkaveh',
        [
          '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(
        'freemodebrandsfourthstkaveh',
        [
          '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(
        'effectbrandsfourthstkaveh',
        [
          '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(
        'showarrowbrandsfourthstkaveh',
        [
          '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(
        'showdotsbrandsfourthstkaveh',
        [
          '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(
        'style2_brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Brand Title Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'textcolor1brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Brand Title Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .best-brands-item .title' => 'color: {{VALUE}}',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'titlety1_brandsfourthstkaveh',
          'label' => esc_html__( 'Brand Title Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .best-brands-item .title',
        ]
      );
      $this->add_control(
        'iconcolor1brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Icon Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .best-brands-item .title i' => 'color: {{VALUE}}',
          ],
        ]
      );
      $this->add_control(
        'iconsize2brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Icon Size', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => 'px',
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 200,
              'step' => 1,
            ],
          ],
          'selectors' => [
            '{{WRAPPER}} .best-brands-item .title i' => 'font-size: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      $this->end_controls_section();
      $this->start_controls_section(
        'style3_brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Brand Box Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'borderradiustbrandsfourthstkaveh',
        [
          'label' => esc_html__( 'Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .best-brands-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
          ],
        ]
      );
      $this->add_control(
        'boxcolor1brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Box Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .best-brands-item' => 'background-color: {{VALUE}}',
          ],
        ]
      );

      $this->add_control(
        'buttonpadding1hover2brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Brand Padding', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .best-brands-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
          ],
        ]
      );
      $this->add_control(
        'catbk1height2brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Box Height', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => [ 'px' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 400,
              'step' => 1,
            ],
          ],
          'selectors' => [
            '{{WRAPPER}} .best-brands-item' => 'height: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      $this->start_controls_tabs(
        'style_tabs2brandsfourthstkaveh'
      );
      
      $this->start_controls_tab(
        'style_normal_tab2brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Normal', 'kavehTheme' ),
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Border::get_type(),
        [
          'name' => 'border2brandsfourthstkaveh',
          'label' => esc_html__( 'Border', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .best-brands-item',
        ]
      );
      $this->add_control(
        'buttonborders2brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Border Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'condition' => [
            'border2brandsfourthstkaveh!' => '',
          ],
          'selectors' => [
            '{{WRAPPER}} .best-brands-item' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->end_controls_tab();
      $this->start_controls_tab(
        'style_hove_tab2brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Hover', 'kavehTheme' ),
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Border::get_type(),
        [
          'name' => 'border1hover2brandsfourthstkaveh',
          'label' => esc_html__( 'Border', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .best-brands-item:hover',
        ]
      );
      $this->add_control(
        'buttonborders1hover2brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Border Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'condition' => [
            'border1hover2brandsfourthstkaveh!' => '',
          ],
          'selectors' => [
            '{{WRAPPER}} .best-brands-item:hover' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      
      $this->end_controls_tab();
      $this->end_controls_tabs();
      $this->end_controls_section();
      $this->start_controls_section(
        'styleimag_brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Brand Image Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'catimg1widthbrandsfourthstkaveh',
        [
          'label' => esc_html__( 'Brand Image Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => [ 'px' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 300,
              'step' => 1,
            ],
          ],
          'selectors' => [
            '{{WRAPPER}} .best-brands-item img' => 'width: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      $this->add_control(
        'catimg1height2brandsfourthstkaveh',
        [
          'label' => esc_html__( 'Brand Image Height', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => [ 'px' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 300,
              'step' => 1,
            ],
          ],
          'selectors' => [
            '{{WRAPPER}} .best-brands-item img' => 'height: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      $this->end_controls_section();

        }
 

  protected function render(){
    $settings = $this->get_settings_for_display();
    $clsid = $this->get_id();
    ?>
    <section class="best-brands">
      <div class="container">
        <!-- Start Carousel -->
        <div class="swiper swiper-best-brands overflow-hidden" data-swiper='<?php echo json_encode([
          "loop" => $settings['loopbrandsfourthstkaveh'] === "yes",
          "autoplay" => $settings['autoplaybrandsfourthstkaveh'] === "yes" ? [
            "delay" => intval($settings['autoplaydelaybrandsfourthstkaveh']),
            "pauseOnMouseEnter" => $settings['pauseonhoverbrandsfourthstkaveh'] === "yes"
          ] : false,
          "speed" => intval($settings['speedbrandsfourthstkaveh']),
          "effect" => $settings['effectbrandsfourthstkaveh'],
          "centeredSlides" => $settings['centeredslidesbrandsfourthstkaveh'] === "yes",
          "freeMode" => $settings['freemodebrandsfourthstkaveh'] === "yes",
          "navigation" => $settings['showarrowbrandsfourthstkaveh'] === "yes" ? [
            "prevEl" => ".swiper-button-prev",
            "nextEl" => ".swiper-button-next"
          ] : false,
          "pagination" => $settings['showdotsbrandsfourthstkaveh'] === "yes" ? [
            "el" => ".swiper-pagination",
            "clickable" => true
          ] : false,
          "breakpoints" => [
            320 => ["slidesPerView" => intval($settings['productcolumn3brandsfourthstkaveh']), "spaceBetween" => 4],
            576 => ["slidesPerView" => intval($settings['productcolumn2brandsfourthstkaveh']), "spaceBetween" => 8],
            768 => ["slidesPerView" => intval($settings['productcolumn2brandsfourthstkaveh']), "spaceBetween" => 12],
            992 => ["slidesPerView" => intval($settings['productcolumnbrandsfourthstkaveh']), "spaceBetween" => 12],
          ]
        ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>'>
          <div class="swiper-wrapper">
            <?php
            if ( $settings['listbrandsfourthstkaveh'] ) {
            foreach (  $settings['listbrandsfourthstkaveh'] as $item ) {
            ?>
            <!-- Start Slide -->
            <div class="swiper-slide">
              <div class="best-brands-item position-relative">
                <a href="<?php echo esc_html($item['linkbrandsfourthstkaveh']); ?>" class="stretched-link" aria-label="brand"></a>
                <img src="<?php echo esc_url($item['img1categorycarouselkaveh']['url']); ?>" alt="<?php echo esc_attr(\Elementor\Control_Media::get_image_alt( $item['img1categorycarouselkaveh'] )); ?>" width="171" height="32" class="d-block mx-auto">
                <<?php echo  esc_attr($item['tagheading1brandsfourthstkaveh']); ?> class="title d-flex align-items-center justify-content-center mb-0">
                  <?php echo  esc_html($item['title1brandsfourthstkaveh']); ?>
                  <i class="<?php echo  esc_html($item['buttonicobrandsfourthstkaveh']['value']); ?> ms-3"></i>
                </<?php echo  esc_attr($item['tagheading1brandsfourthstkaveh']); ?>>
              </div>
            </div>
            <!-- End Slide -->
            <?php 
            }
              }
            ?>
          </div>
          <?php if($settings['showarrowbrandsfourthstkaveh'] === 'yes'){ ?>
            <div class="swiper-button-prev"></div>
            <div class="swiper-button-next"></div>
          <?php } ?>
          <?php if($settings['showdotsbrandsfourthstkaveh'] === 'yes'){ ?>
            <div class="swiper-pagination"></div>
          <?php } ?>
        </div>
        <!-- End Carousel -->
      </div>
    </section>
    

    <?php
  }


}
