<?php



use Elementor\Widget_Base;
use Elementor\Controls_Manager;

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


class Categorycarouselfourthstkaveh extends Widget_Base{

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

  public function get_title(){
    return esc_html__( 'Category 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(
        'contentcategorycarouselfourthstkaveh',
        [
          'label' => esc_html__( 'Element Content', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );

        $this->add_control(
          'titlecategorycarouselfourthstkaveh',
          [
            'label' => esc_html__( 'Title', 'kavehTheme' ),
            'type' => \Elementor\Controls_Manager::TEXT,
            'default' => 'Categories',
    
          ]
        );
        $this->add_control(
          'tagheadingcategorycarouselfourthstkaveh',
          [
            'label' => esc_html__( 'Title Tag', 'kavehTheme' ),
            'type' => \Elementor\Controls_Manager::SELECT,
            'default' => 'H3',
            '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(
          'imgbgcategorycarouselfourthstkave',
          [
            'label' => esc_html__( 'Title Background Image', 'kavehTheme' ),
            'type' => \Elementor\Controls_Manager::MEDIA,
            'selectors' => [
              '{{WRAPPER}} .categories-sixteen-title::before' =>
                  'background: url({{URL}})',
          ],
          ]
        );
        
      $repeater = new \Elementor\Repeater();
    $repeater->add_control(
      'imgcategorycarouselfourthstkaveh',
      [
        'label' => esc_html__( 'Select Your Image', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::MEDIA,
        'default' => [
          'url' => \Elementor\Utils::get_placeholder_image_src(),
        ],
      ]
    );
    $repeater->add_control(
      'linkcategorycarouselfourthstkaveh',
      [
        'label' => esc_html__( 'Link', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => '#',
      ]
    );
    $this->add_control(
      'listcategorycarouselfourthstkaveh',
      [
        'label' => esc_html__( 'Categories', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::REPEATER,
        'fields' => $repeater->get_controls(),
        'default' => [
          [
            'linkcategorycarouselfourthstkaveh' => esc_html__( '#', 'kavehTheme' ),
          ],
      ]
      ]
    
    ); 
       $this->end_controls_section();
       $this->start_controls_section(
        'content4categorycarouselfourthstkaveh',
        [
          'label' => esc_html__( 'Carousel Settings', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
      $this->add_control(
        'productcolumncategorycarouselfourthstkaveh',
        [
          'label' => esc_html__( 'Number of Product Columns on Desktop', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 0,
          'max' => 5,
          'step' => 0.5,
          'default' => 4,
      
        ]
      ); 
      $this->add_control(
        'productcolumn2categorycarouselfourthstkaveh',
        [
          '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(
        'productcolumn3categorycarouselfourthstkaveh',
        [
          'label' => esc_html__( 'Number of Product Columns on Mobile', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::NUMBER,
          'min' => 0,
          'max' => 5,
          'step' => 0.5,
          'default' => 1.5,
      
        ]
      );
             $this->end_controls_section();
       $this->start_controls_section(
        'style3_categorycarouselfourthstkaveh',
        [
          'label' => esc_html__( 'Image Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'imgsizecategorycarouselfourthstkaveh',
        [
          'label' => esc_html__( 'Category Image Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => [ 'px', '%' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 1000,
              'step' => 1,
            ],
            '%' => [
              'min' => 0,
              'max' => 100,
            ],
          ],
          'default' => [
            'unit' => 'px',
            'size' => 294,
          ],
          'selectors' => [
            '{{WRAPPER}} .catca4' => 'width: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      
      $this->end_controls_section();
      $this->start_controls_section(
        'style4_categorycarouselfourthstkaveh',
        [
          'label' => esc_html__( 'Title Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'imgbgsizecategorycarouselfourthstkaveh',
        [
          'label' => esc_html__( 'Title Background Image Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'size_units' => [ 'px', '%' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 2000,
              'step' => 1,
            ],
            '%' => [
              'min' => 0,
              'max' => 100,
            ],
          ],
          'default' => [
            'unit' => 'px',
            'size' => 384,
          ],
          'selectors' => [
            '{{WRAPPER}} .categories-sixteen-title::before' => 'max-width: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'title_categorycarouselfourthstkaveh',
          'label' => esc_html__( 'Title Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .categories-sixteen-title',
        ]
      );
      $this->add_control(
        'tccolorcategorycarouselfourthstkaveh',
        [
          'label' => esc_html__( 'Title Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .categories-sixteen-title' => 'color: {{VALUE}}',
          ],
        ]
      );
      $this->end_controls_section();
        }


  protected function render(){
    $settings = $this->get_settings_for_display();
    $clsid = $this->get_id();
    ?>
<div class="categories-sixteen">
      <div class="container">
        <<?php echo  esc_attr($settings['tagheadingcategorycarouselfourthstkaveh']); ?> class="categories-sixteen-title position-relative">
        <?php echo  esc_html($settings['titlecategorycarouselfourthstkaveh']); ?>
        </<?php echo  esc_attr($settings['tagheadingcategorycarouselfourthstkaveh']); ?>>
        <div class="swiper swiper-categories-sixteen overflow-hidden" data-swiper='{"breakpoints":{"320":{"slidesPerView":<?php echo  esc_html($settings['productcolumn3categorycarouselfourthstkaveh']); ?>,"spaceBetween":8},"500":{"slidesPerView":<?php echo  esc_html($settings['productcolumn2categorycarouselfourthstkaveh']); ?>,"spaceBetween":8},"768":{"slidesPerView":<?php echo  esc_html($settings['productcolumn2categorycarouselfourthstkaveh']); ?>,"spaceBetween":12},"992":{"slidesPerView":<?php echo  esc_html($settings['productcolumncategorycarouselfourthstkaveh']); ?>,"spaceBetween":30}}}'>
          <div class="swiper-wrapper">
          <?php
              if ( $settings['listcategorycarouselfourthstkaveh'] ) {
              foreach (  $settings['listcategorycarouselfourthstkaveh'] as $item ) {
              ?>
            <!-- Start Category -->
            <div class="swiper-slide">
              <a href="<?php echo  esc_url($item['linkcategorycarouselfourthstkaveh']); ?>" class="d-block">
                <img src="<?php echo esc_url($item['imgcategorycarouselfourthstkaveh']['url']); ?>" alt="<?php echo esc_attr(\Elementor\Control_Media::get_image_alt( $item['imgcategorycarouselfourthstkaveh'] )); ?>" class="d-block catca4" />
              </a>
            </div>
            <!-- End Category -->
            <?php 
            }
              }
            ?>
          </div>
          <div class="swiper-button-next d-none"></div>
          <div class="swiper-button-prev d-none"></div>
        </div>
      </div>
    </div>
    <style>
      <?php echo '.elementor-element-' . $clsid . ''; ?> .categories-sixteen-title::before {
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    object-fit: cover;
}
    </style>
    
    <?php
  }


}
