<?php



use Elementor\Widget_Base;
use Elementor\Controls_Manager;

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


class Sliderfirstkaveh extends Widget_Base{

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

  public function get_title(){
    return esc_html__( 'First Style Slider', 'kavehTheme' );
  }

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

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

  protected function register_controls(){
    
    $this->start_controls_section(
        'contentsliderfirstkaveh',
        [
          'label' => esc_html__( 'Content', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
      $this->add_control(
        'style1sliderfirstkaveh',
        [
          'label' => esc_html__( 'Slider Layout', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SELECT,
          'default' => 'one',
          'options' => [
            'one'  => esc_html__( 'First Layout', 'kavehTheme' ),
						'two'  => esc_html__( 'Second Layout', 'kavehTheme' ),
						'three'  => esc_html__( 'Third Layout', 'kavehTheme' ),
						'four'  => esc_html__( 'Fourth Layout', 'kavehTheme' ),
    
          ],
        ]
        ); 
      $repeater = new \Elementor\Repeater();

      $repeater->add_control(
        'backsliderfirstkaveh',
        [
          'label' => esc_html__( 'Select Your Image', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::MEDIA,
          'default' => [
            'url' => \Elementor\Utils::get_placeholder_image_src(),
          ],
        ]
      );
      $repeater->add_control(
        'linksliderfirstkaveh',
        [
            'label' => esc_html__( 'Slide Link', 'kavehTheme' ),
            'type' => \Elementor\Controls_Manager::TEXT,
            'default' => esc_html__( '#', 'kavehTheme' ),
    
        ]
    );
      $this->add_control(
        'slidessliderfirstkaveh',
        [
          'label' => esc_html__( 'Slides', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::REPEATER,
          'fields' => $repeater->get_controls(),
          ],
      );
      $this->add_control(
        'arrowssliderfirstkaveh',
        [
          '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' => 'yes',
        ]
      );
      $this->add_control(
        'bulletssliderfirstkaveh',
        [
          'label' => esc_html__( 'Show Dots?', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SWITCHER,
          'yes' => esc_html__( 'Yes', 'kavehTheme' ),
          'no' => esc_html__( 'No', 'kavehTheme' ),
          'return_value' => 'yes',
          'default' => 'yes',
          'condition' => [
            'style1sliderfirstkaveh' => ['one','three','four'],
          ],
        ]
      );
      $this->end_controls_section();

      $this->start_controls_section(
        'style1_sliderfirstkaveh',
        [
          'label' => esc_html__( 'Slider Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'heightbgsliderfirstkaveh',
        [
          'label' => esc_html__( 'Slider Height', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'condition' => [
            'style1sliderfirstkaveh' => 'one',
          ],
          'size_units' => [ 'px' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 2000,
              'step' => 5,
            ],
            '%' => [
              'min' => 0,
              'max' => 100,
            ],
          ],
          'default' => [
            'unit' => '%',
            'size' => 100,
          ],
          'selectors' => [
            '{{WRAPPER}} .slider-banner-home .carousel, .slider-banner-home .carousel-inner, .slider-banner-home .carousel-item, .slider-banner-home .carousel-item img' => 'height: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      $this->add_control(
        'height2bgsliderfirstkaveh',
        [
          'label' => esc_html__( 'Slider Height', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'condition' => [
            'style1sliderfirstkaveh' => 'two',
          ],
          'size_units' => [ 'px', '%' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 2000,
              'step' => 5,
            ],
            '%' => [
              'min' => 0,
              'max' => 100,
            ],
          ],
          'default' => [
            'unit' => '%',
            'size' => 100,
          ],
          'selectors' => [
            '{{WRAPPER}} .slider-home img' => 'height: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
      $this->add_control(
        'height3bgsliderfirstkaveh',
        [
          'label' => esc_html__( 'Slider Height', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'condition' => [
            'style1sliderfirstkaveh' => 'three',
          ],
          'size_units' => [ 'px', '%' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 2000,
              'step' => 5,
            ],
            '%' => [
              'min' => 0,
              'max' => 100,
            ],
          ],
          'default' => [
            'unit' => '%',
            'size' => 100,
          ],
          'selectors' => [
            '{{WRAPPER}} .category-slider-banner .left .carousel-item img' => 'height: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
    
      $this->add_control(
        'height4bgsliderfirstkaveh',
        [
          'label' => esc_html__( 'Slider Height', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SLIDER,
          'condition' => [
            'style1sliderfirstkaveh' => 'four',
          ],
          'size_units' => [ 'px', '%' ],
          'range' => [
            'px' => [
              'min' => 0,
              'max' => 2000,
              'step' => 5,
            ],
            '%' => [
              'min' => 0,
              'max' => 100,
            ],
          ],
          'default' => [
            'unit' => '%',
            'size' => 100,
          ],
          'selectors' => [
            '{{WRAPPER}} .slider-banners-ten-item img' => 'height: {{SIZE}}{{UNIT}};',
          ],
        ]
      );
       $this->end_controls_section();

          
        }


  protected function render(){
    $settings = $this->get_settings_for_display();
    $clsid = $this->get_id();
    ?>
      <?php if('one'===$settings['style1sliderfirstkaveh']){ ?>
       <div class="slider-banner-home">
            <div id="slider-home<?php echo $clsid; ?>" class="carousel carousel-fade" data-bs-ride="carousel">
            <?php if("yes"===$settings['bulletssliderfirstkaveh']){?>
              <div class="carousel-indicators d-none d-md-block">
              <?php
              $j=0;
              if ( $settings['slidessliderfirstkaveh'] ) {
              foreach (  $settings['slidessliderfirstkaveh'] as $item ) {
              ?>
                <button type="button" data-bs-target="#slider-home<?php echo $clsid; ?>" data-bs-slide-to="<?php echo $j; ?>" class="<?php if($j==0){ ?>active<?php }else{}?>"
                  aria-current="true" aria-label="Slide <?php echo $j; ?>"></button>
                  <?php
                $j++;
                }
              }
                ?>
              </div>
              <?php } ?>
              <div class="carousel-inner">
              <?php
              $i=0;
              if ( $settings['slidessliderfirstkaveh'] ) {
              foreach (  $settings['slidessliderfirstkaveh'] as $item ) {
              ?>
                <div class="carousel-item <?php if($i==0){ ?>active<?php }else{}?>">
                  <a href="<?php echo  esc_url($item['linksliderfirstkaveh']); ?>">
                    <img src="<?php echo esc_url($item['backsliderfirstkaveh']['url']); ?>" class="d-block w-100" alt="<?php echo esc_attr(\Elementor\Control_Media::get_image_alt( $item['backsliderfirstkaveh'] )); ?>">
                  </a>
                </div>
                <?php
                $i++;
                }
              }
                ?>
        </div>
              <?php if("yes"===$settings['arrowssliderfirstkaveh']){?>
              <button class="carousel-control-prev d-none d-md-block" type="button" data-bs-target="#slider-home<?php echo $clsid; ?>"
                data-bs-slide="prev">
                <i class="icon-angle-right"></i>
              </button>
              <button class="carousel-control-next d-none d-md-block" type="button" data-bs-target="#slider-home<?php echo $clsid; ?>"
                data-bs-slide="next">
                <i class="icon-angle-left"></i>
              </button>
          <?php } ?>
            </div>
          </div>
  <?php }elseif('two'===$settings['style1sliderfirstkaveh']){ ?>
    <div class="slider-home">
      <div class="swiper swiper-slider-home position-relative"
      data-swiper='{
    "slidesPerView": 1,
    "spaceBetween": 0,
    "autoplay": {
      "delay": 5000,
      "disableOnInteraction": false,
      "pauseOnMouseEnter": true
    },
    "effect": "fade",
    "fadeEffect": {
      "crossFade": true
    },
    "loop": true,
    "navigation": {
      "nextEl": ".swiper-button-next",
      "prevEl": ".swiper-button-prev"
    }
  }'>
        <div class="swiper-wrapper">
        <?php
              if ( $settings['slidessliderfirstkaveh'] ) {
              foreach (  $settings['slidessliderfirstkaveh'] as $item ) {
              ?>
          <div class="swiper-slide">
            <a href="<?php echo  esc_url($item['linksliderfirstkaveh']); ?>">
              <img src="<?php echo esc_url($item['backsliderfirstkaveh']['url']); ?>" alt="<?php echo esc_attr(\Elementor\Control_Media::get_image_alt( $item['backsliderfirstkaveh'] )); ?>" class="w-100 d-block" />
            </a>
          </div>
          <?php
                }
              }
                ?>
        </div>
        <?php if("yes"===$settings['arrowssliderfirstkaveh']){?>
        <div class="swiper-button-next d-none d-md-flex"></div>
        <div class="swiper-button-prev d-none d-md-flex"></div>
        <?php } ?>

      </div>
    </div>
    <?php }elseif('three'===$settings['style1sliderfirstkaveh']){ ?>
     <section class="category-slider-banner"> 
      <div class="left">
          <div id="slider-eight<?php echo $clsid; ?>" class="carousel carousel-fade" data-bs-ride="carousel">
          <?php if("yes"===$settings['bulletssliderfirstkaveh']){?>
            <div class="carousel-indicators">
            <?php
              $j=0;
              if ( $settings['slidessliderfirstkaveh'] ) {
              foreach (  $settings['slidessliderfirstkaveh'] as $item ) {
              ?>
              <button type="button" data-bs-target="#slider-eight<?php echo $clsid; ?>" data-bs-slide-to="<?php echo $j ; ?>" class="<?php if($j==0){ ?>active<?php }else{}?>"
                aria-current="true" aria-label="Slide <?php echo $j ;?>"></button>
                <?php
                $j++;
                }
              }
                ?>
            </div>
            <?php } ?>
            <div class="carousel-inner">
            <?php
              $i=0;
              if ( $settings['slidessliderfirstkaveh'] ) {
              foreach (  $settings['slidessliderfirstkaveh'] as $item ) {
              ?>
              <div class="carousel-item <?php if($i==0){ ?>active<?php }else{}?>">
              <a href="<?php echo  esc_url($item['linksliderfirstkaveh']); ?>">
                <img src="<?php echo esc_url($item['backsliderfirstkaveh']['url']); ?>" class="d-block w-100" alt="<?php echo esc_attr(\Elementor\Control_Media::get_image_alt( $item['backsliderfirstkaveh'] )); ?>" />
                </a>
              </div>
              <?php
                $i++;
                }
              }
                ?>
            </div>
            <?php if("yes"===$settings['arrowssliderfirstkaveh']){?>
            <button class="carousel-control-prev" type="button" data-bs-target="#slider-eight<?php echo $clsid; ?>" data-bs-slide="prev">
              <i class="icon-angle-right"></i>
            </button>
            <button class="carousel-control-next" type="button" data-bs-target="#slider-eight<?php echo $clsid; ?>" data-bs-slide="next">
              <i class="icon-angle-left"></i>
            </button>
            <?php } ?>
          </div>
          </div>
     </section>
          <?php }elseif('four'===$settings['style1sliderfirstkaveh']){ ?>
    <div class="slider-banners-ten">
      <div class="container">
        <!-- Start Carousel -->
        <div class="swiper swiper-slider-ten position-relative"
        data-swiper='{
    "loop": true,
    "navigation": {
      "nextEl": ".swiper-button-next",
      "prevEl": ".swiper-button-prev"
    },
    "slidesPerView": 1,
    "spaceBetween": 0,
    "pagination": {
      "el": ".swiper-pagination",
      "type": "bullets",
      "clickable": true
    },
    "autoplay": {
      "delay": 3000
    },
    "effect": "fade",
    "fadeEffect": {
      "crossFade": true
    }
  }'>
          <div class="swiper-wrapper">
          <?php
              if ( $settings['slidessliderfirstkaveh'] ) {
              foreach (  $settings['slidessliderfirstkaveh'] as $item ) {
              ?>
            <!-- Start Slide -->
            <div class="swiper-slide">
              <div class="slider-banners-ten-item">
                <a href="<?php echo  esc_url($item['linksliderfirstkaveh']); ?>">
                  <img src="<?php echo esc_url($item['backsliderfirstkaveh']['url']); ?>" alt="<?php echo esc_attr(\Elementor\Control_Media::get_image_alt( $item['backsliderfirstkaveh'] )); ?>" class="d-block w-100" />
                </a>
              </div>
            </div>
            <!-- End Slide -->
            <?php
                }
              }
                ?>
          </div>
          <div class="swiper-bottom d-flex align-items-center justify-content-center">
          <?php if("yes"===$settings['arrowssliderfirstkaveh']){?>
            <div class="swiper-button-prev"></div>
            <?php } ?>
          <?php if("yes"===$settings['bulletssliderfirstkaveh']){?>

            <div class="swiper-pagination"></div>
            <?php } ?>

            <?php if("yes"===$settings['arrowssliderfirstkaveh']){?>
            <div class="swiper-button-next"></div>
            <?php } ?>
          </div>
        </div>
        <!-- End Carousel -->
      </div>
    </div>
    <?php } 
  }


}
