<?php



use Elementor\Widget_Base;
use Elementor\Controls_Manager;

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


class Brandscarouselkaveh extends Widget_Base{

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

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

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

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

  protected function register_controls(){
    
    $this->start_controls_section(
        'contentbrandscarouselkaveh',
        [
          'label' => esc_html__( 'Element Content', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
      $this->add_control(
        'stylebrandscarouselkaveh',
        [
          'label' => esc_html__( 'Brands Layout', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SELECT,
          'default' => 'one',
          'options' => [
            'one'  => esc_html__( 'First Layout', 'kavehTheme' ),
           'two'  => esc_html__( 'Second Layout', 'kavehTheme' ),    
          ],
        ]
        );
        $this->add_control(
          'arrowbrandscarouselkaveh',
          [
            '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',
            'condition' => [
              'stylebrandscarouselkaveh' => 'one',
            ],
          ]
        ); 
        $this->add_control(
          'titlebrandscarouselkaveh',
          [
              'label' => esc_html__( 'Title', 'kavehTheme' ),
              'type' => \Elementor\Controls_Manager::TEXT,
              'default' => esc_html__( 'Brands', 'kavehTheme' ),
              'condition' => [
                'stylebrandscarouselkaveh' => 'two',
              ],
      
          ]
      );
      $this->add_control(
        'tagheadingbrandscarouselkaveh',
        [
          'label' => esc_html__( 'Title Tag', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SELECT,
          'condition' => [
            'stylebrandscarouselkaveh' => 'two',
          ],
          'default' => 'H4',
          'options' => [
            'H1'  => esc_html__( 'H1', 'kavehTheme' ),
            'H2' => esc_html__( 'H2', 'kavehTheme' ),
            'H3' => esc_html__( 'H3', 'kavehTheme' ),
            'H4' => esc_html__( 'H4', 'kavehTheme' ),
            'H5' => esc_html__( 'H5', 'kavehTheme' ),
            'H6' => esc_html__( 'H6', 'kavehTheme' ),
            'p' => esc_html__( 'p', 'kavehTheme' ),
            'div' => esc_html__( 'div', 'kavehTheme' ),
          ],
        ]
      );
      $repeater = new \Elementor\Repeater();

      $repeater->add_control(
        'brandlogobrandscarouselkaveh',
        [
          'label' => esc_html__( 'Brand Image', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::MEDIA,
        ]
        );
        $repeater->add_control(
          'linkbrandscarouselkaveh',
          [
              'label' => esc_html__( 'Brand Link', 'kavehTheme' ),
              'type' => \Elementor\Controls_Manager::TEXT,
              'default' => esc_html__( '#', 'kavehTheme' ),
      
          ]
      );
    $this->add_control(
      'listbrandscarouselkaveh',
      [
        'label' => esc_html__( 'Categories', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::REPEATER,
        'fields' => $repeater->get_controls(),
        'default' => [
          [
            'linkbrandscarouselkaveh' => esc_html__( '#', 'kavehTheme' ),
          ],
      ]
      ]
    
    );
       $this->end_controls_section();
       $this->start_controls_section(
        'content3brandscarouselkaveh',
        [
          'label' => esc_html__( 'Carousel Settings', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
      $this->add_control(
        'productcolumnbrandscarouselkaveh',
        [
          'label' => esc_html__( 'Number of Brand Columns on Desktop', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 0,
          'max' => 7,
          'step' => 1,
          'default' => 4,
      
        ]
      );
      $this->add_control(
        'productcolumn2brandscarouselkaveh',
        [
          '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(
        'productcolumn3brandscarouselkaveh',
        [
          '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(
        'autoplaybrandscarouselkaveh',
        [
          '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(
        'autoplaydelaybrandscarouselkaveh',
        [
          'label' => esc_html__( 'Autoplay Delay (milliseconds)', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 1000,
          'max' => 10000,
          'step' => 500,
          'default' => 3000,
          'condition' => [
            'autoplaybrandscarouselkaveh' => 'yes',
          ],
        ]
      );
      $this->add_control(
        'pauseonhoverbrandscarouselkaveh',
        [
          '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' => [
            'autoplaybrandscarouselkaveh' => 'yes',
          ],
        ]
      );
      $this->add_control(
        'loopbrandscarouselkaveh',
        [
          '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(
        'speedbrandscarouselkaveh',
        [
          'label' => esc_html__( 'Transition Speed (milliseconds)', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 300,
          'max' => 3000,
          'step' => 100,
          'default' => 300,
        ]
      );
      $this->add_control(
        'centeredslidesbrandscarouselkaveh',
        [
          '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(
        'freemodebrandscarouselkaveh',
        [
          '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(
        'effectbrandscarouselkaveh',
        [
          '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(
        'showarrowbrandscarouselkaveh',
        [
          '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(
        'showdotsbrandscarouselkaveh',
        [
          '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_tbrandscarouselkaveh',
        [
          'label' => esc_html__( 'Title Style', 'kavehTheme' ),
          'condition' => [
            'stylebrandscarouselkaveh' => 'two',
          ],
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      ); 
      $this->add_control(
        'title1stbrandscarouselkaveh',
        [
          'label' => esc_html__( 'Title Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .brands-two .brands-wrapper .title' => 'color: {{VALUE}}',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'title1_brandscarouselkaveh',
          'label' => esc_html__( 'Title Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .brands-two .brands-wrapper .title',
        ]
      ); 

      $this->end_controls_section();

       $this->start_controls_section(
        'style_brandscarouselkaveh',
        [
          'label' => esc_html__( 'Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'buttonpaddingbordersbrandscarouselkaveh',
        [
          'label' => esc_html__( 'Box Padding', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .brands-wrapper' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->add_control(
        'buttonradiusbrandscarouselkaveh',
        [
          'label' => esc_html__( 'Box Border Radius', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .brands-wrapper' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Border::get_type(),
        [
          'name' => 'borderbrandscarouselkaveh',
          'label' => esc_html__( 'Border', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .brands-wrapper',
        ]
      );
      $this->add_control(
        'buttonbordersbrandscarouselkaveh',
        [
          'label' => esc_html__( 'Border Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'condition' => [
            'borderbrandscarouselkaveh!' => '',
          ],
          'selectors' => [
            '{{WRAPPER}} .brands-wrapper' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Box_Shadow::get_type(),
        [
          'name' => 'box_shadowbrandscarouselkaveh',
          'label' => esc_html__( 'Box Shadow', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .brands-wrapper',
        ]
      );
      $this->end_controls_section();

        }


  protected function render(){
    $settings = $this->get_settings_for_display();
    $clsid = $this->get_id();
    ?>
      <?php if('one'===$settings['stylebrandscarouselkaveh']){ ?>
      <div class="brands">
        <div class="container">
        <div class="brands-wrapper position-relative">
            <div class="swiper swiper-brands overflow-hidden" data-swiper='<?php echo json_encode([
              "loop" => $settings['loopbrandscarouselkaveh'] === "yes",
              "autoplay" => $settings['autoplaybrandscarouselkaveh'] === "yes" ? [
                "delay" => intval($settings['autoplaydelaybrandscarouselkaveh']),
                "pauseOnMouseEnter" => $settings['pauseonhoverbrandscarouselkaveh'] === "yes"
              ] : false,
              "speed" => intval($settings['speedbrandscarouselkaveh']),
              "effect" => $settings['effectbrandscarouselkaveh'],
              "centeredSlides" => $settings['centeredslidesbrandscarouselkaveh'] === "yes",
              "freeMode" => $settings['freemodebrandscarouselkaveh'] === "yes",
              "navigation" => $settings['showarrowbrandscarouselkaveh'] === "yes" ? [
                "prevEl" => ".swiper-button-prev",
                "nextEl" => ".swiper-button-next"
              ] : false,
              "pagination" => $settings['showdotsbrandscarouselkaveh'] === "yes" ? [
                "el" => ".swiper-pagination",
                "clickable" => true
              ] : false,
              "breakpoints" => [
                320 => ["slidesPerView" => intval($settings['productcolumn3brandscarouselkaveh']), "spaceBetween" => 4],
                576 => ["slidesPerView" => intval($settings['productcolumn2brandscarouselkaveh']), "spaceBetween" => 8],
                768 => ["slidesPerView" => intval($settings['productcolumn2brandscarouselkaveh']), "spaceBetween" => 12],
                992 => ["slidesPerView" => intval($settings['productcolumnbrandscarouselkaveh']), "spaceBetween" => 12],
              ]
            ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>'>
            <div class="swiper-wrapper">
                <?php
                if ( $settings['listbrandscarouselkaveh'] ) {
                foreach (  $settings['listbrandscarouselkaveh'] as $item ) {
                ?>
                <div class="swiper-slide">
                <a href="<?php echo  esc_html($item['linkbrandscarouselkaveh']); ?>" class="brands-item d-block">
                    <img src="<?php echo esc_url($item['brandlogobrandscarouselkaveh']['url']); ?>" alt="<?php echo esc_attr(\Elementor\Control_Media::get_image_alt( $item['brandlogobrandscarouselkaveh'] )); ?>" />
                </a>
                </div>
                <?php 
            }
            }
            ?>
            </div>
            <?php if($settings['showarrowbrandscarouselkaveh'] === 'yes'){ ?>
            <div class="swiper-button-next"></div>
            <div class="swiper-button-prev"></div>
            <?php } ?>
            <?php if($settings['showdotsbrandscarouselkaveh'] === 'yes'){ ?>
              <div class="swiper-pagination"></div>
            <?php } ?>
            </div>
        </div>
        </div>
    </div>
    <?php }elseif('two'===$settings['stylebrandscarouselkaveh']){ ?>
     <div class="brands brands-two">
      <div class="container">
        <div class="brands-wrapper position-relative">
          <<?php echo  esc_attr($settings['tagheadingbrandscarouselkaveh']); ?> class="title"> <?php echo  esc_html($settings['titlebrandscarouselkaveh']); ?> </<?php echo  esc_attr($settings['tagheadingbrandscarouselkaveh']); ?>>
          <div class="swiper swiper-brands overflow-hidden" data-swiper='<?php echo json_encode([
            "loop" => $settings['loopbrandscarouselkaveh'] === "yes",
            "autoplay" => $settings['autoplaybrandscarouselkaveh'] === "yes" ? [
              "delay" => intval($settings['autoplaydelaybrandscarouselkaveh']),
              "pauseOnMouseEnter" => $settings['pauseonhoverbrandscarouselkaveh'] === "yes"
            ] : false,
            "speed" => intval($settings['speedbrandscarouselkaveh']),
            "effect" => $settings['effectbrandscarouselkaveh'],
            "centeredSlides" => $settings['centeredslidesbrandscarouselkaveh'] === "yes",
            "freeMode" => $settings['freemodebrandscarouselkaveh'] === "yes",
            "navigation" => $settings['showarrowbrandscarouselkaveh'] === "yes" ? [
              "prevEl" => ".swiper-button-prev",
              "nextEl" => ".swiper-button-next"
            ] : false,
            "pagination" => $settings['showdotsbrandscarouselkaveh'] === "yes" ? [
              "el" => ".swiper-pagination",
              "clickable" => true
            ] : false,
            "breakpoints" => [
              320 => ["slidesPerView" => intval($settings['productcolumn3brandscarouselkaveh']), "spaceBetween" => 4],
              576 => ["slidesPerView" => intval($settings['productcolumn2brandscarouselkaveh']), "spaceBetween" => 8],
              768 => ["slidesPerView" => intval($settings['productcolumn2brandscarouselkaveh']), "spaceBetween" => 12],
              992 => ["slidesPerView" => intval($settings['productcolumnbrandscarouselkaveh']), "spaceBetween" => 12],
            ]
          ], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>'>
            <div class="swiper-wrapper">
            <?php
                if ( $settings['listbrandscarouselkaveh'] ) {
                foreach (  $settings['listbrandscarouselkaveh'] as $item ) {
                ?>
              <div class="swiper-slide">
                <a href="<?php echo  esc_url($item['linkbrandscarouselkaveh']); ?>" class="brands-item d-block">
                  <img src="<?php echo esc_url($item['brandlogobrandscarouselkaveh']['url']); ?>" alt="<?php echo esc_attr(\Elementor\Control_Media::get_image_alt( $item['brandlogobrandscarouselkaveh'] )); ?>" />
                </a>
              </div>
              <?php 
            }
            }
            ?>
            </div>
            <div class="swiper-button-next d-none"></div>
            <div class="swiper-button-prev d-none"></div>
            <?php if($settings['showdotsbrandscarouselkaveh'] === 'yes'){ ?>
              <div class="swiper-pagination"></div>
            <?php } ?>
          </div>
        </div>
      </div>
    </div>
      <?php } ?>
   

    <?php
    if(empty($settings['borderbrandscarouselkaveh'])){ ?>
 <style>
  <?php echo '.elementor-element-' . $clsid . ''; ?> .brands-wrapper{
    border-width:0;
  }
 </style>
    <?php
        }
        ?>
    <?php
  }


}
