<?php

use Elementor\Widget_Base;
use Elementor\Controls_Manager;

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


class Blogcarouselsecondstkaveh extends Widget_Base{

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

  public function get_title(){
    return esc_html__( 'Blog Carousel Element 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(
        'contentblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Titles', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
   
      $this->add_control(
          'title1blogcarouselsecondstkaveh',
          [
              'label' => esc_html__( 'Title', 'kavehTheme' ),
              'type' => \Elementor\Controls_Manager::TEXT,
              'default' => esc_html__( 'Latest', 'kavehTheme' ),
      
          ]
      );
      $this->add_control(
        'tagheading1blogcarouselsecondstkaveh',
        [
          '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(
        'title2blogcarouselsecondstkaveh',
        [
            'label' => esc_html__( 'Marked Title', 'kavehTheme' ),
            'type' => \Elementor\Controls_Manager::TEXT,
            'default' => esc_html__( 'Articles', 'kavehTheme' ),
    
        ]
    );
    $this->add_control(
      'tagheading2blogcarouselsecondstkaveh',
      [
        'label' => esc_html__( 'Marked 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(
      'title3blogcarouselsecondstkaveh',
      [
          'label' => esc_html__( 'Subtitle', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::TEXT,
          'default' => esc_html__( 'Educational', 'kavehTheme' ),
  
      ]
  );
  $this->add_control(
    'linktitle3blogcarouselsecondstkaveh',
    [
        'label' => esc_html__( 'Subtitle Link', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::TEXT,
        'default' => esc_html__( '#', 'kavehTheme' ),

    ]
);
      $this->add_control(
        'moreblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Show More Button?', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::SWITCHER,
          'yes' => esc_html__( 'Yes', 'kavehTheme' ),
          'no' => esc_html__( 'No', 'kavehTheme' ),
          'return_value' => 'yes',
          'default' => 'yes',
        ]
      );
      $this->add_control(
        'buttonblogcarouselsecondstkaveh',
        [
            'label' => esc_html__( 'Button', 'kavehTheme' ),
            'type' => \Elementor\Controls_Manager::TEXT,
            'default' => esc_html__( 'Read More', 'kavehTheme' ),
            'condition' => [
              'moreblogcarouselsecondstkaveh' => 'yes',
            ],
    
        ]
    );
    $this->add_control(
      'buttonlinkblogcarouselsecondstkaveh',
      [
          'label' => esc_html__( 'Button Link', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::TEXT,
          'default' => esc_html__( '#', 'kavehTheme' ),
          'condition' => [
            'moreblogcarouselsecondstkaveh' => 'yes',
          ],
  
      ]
  );
 
  $this->end_controls_section();

  $this->start_controls_section(
    'content3blogcarouselsecondstkaveh',
    [
      'label' => esc_html__( 'Blog Settings', 'kavehTheme' ),
              'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
    ]
  );
  $optionsblog = array();
  $categories = get_categories(array(
    'hide_empty' => false,
  )
  ); 
  foreach ( $categories as $key => $category ) {
      $optionsblog[$category->term_id] = $category->name;
  }
  $this->add_control(
      'catblogenfhess',
      [
        'label' => esc_html__( 'Select Category', 'kavehTheme' ),
        'type' => \Elementor\Controls_Manager::SELECT2, 
        'multiple' => true,
        'options' => $optionsblog,
      ]
  );
  
$this->add_control(
  'productnumberblogcarouselsecondstkaveh',
  [
    'label' => esc_html__( 'Number of Products Displayed', 'kavehTheme' ),
    'type' => \Elementor\Controls_Manager::NUMBER,
    'min' => 0,
    'max' => 20,
    'step' => 1,
    'default' => 5,
  ]
);
       $this->end_controls_section();
       $this->start_controls_section(
        'content4blogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Image', 'kavehTheme' ),
                  'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
        ]
      );
      $this->add_control(
        'bgimgblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Product Card Background Image', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::MEDIA,
          'selectors' => [
            '{{WRAPPER}} .article-six figure::after' =>
                'background-image: url({{URL}})',
        ],
        ]
        );

      $this->end_controls_section();

       $this->start_controls_section(
        'style1_blogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Title Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
        ]
      );
      $this->add_control(
        'titlestblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Title Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .sup-title' => 'color: {{VALUE}}',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'title_blogcarouselsecondstkaveh',
          'label' => esc_html__( 'Title Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .new-articles-blog .right .sup-title',
        ]
      );
      
      $this->add_control(
        'title2stblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Marked Section Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .title::before' => 'background-color: {{VALUE}}',
          ],
        ]
      );
      $this->add_control(
        'title3stblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Marked Section Text Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .title' => 'color: {{VALUE}}',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'titletypo2_blogcarouselsecondstkaveh',
          'label' => esc_html__( 'Marked Section Text Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .new-articles-blog .right .title',
        ]
      );
      $this->add_control(
        'title31stblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Second Title Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .read-more' => 'color: {{VALUE}}',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'title3_blogcarouselsecondstkaveh',
          'label' => esc_html__( 'Second Title Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .new-articles-blog .right .read-more',
        ]
      );
      $this->end_controls_section();
      $this->start_controls_section(
        'style2_blogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Button Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
          'condition' => [
            'moreblogcarouselsecondstkaveh' => 'yes',
          ],
        ]
      );
      
      $this->add_group_control(
        \Elementor\Group_Control_Typography::get_type(),
        [
          'name' => 'button_blogcarouselsecondstkaveh',
          'label' => esc_html__( 'Button Text Typography', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .new-articles-blog .right .btn',
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Text_Shadow::get_type(),
        [
          'name' => 'text_shadowblogcarouselsecondstkaveh',
          'label' => esc_html__( 'Text Shadow', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .new-articles-blog .right .btn',
        ]
      );
      $this->start_controls_tabs(
        'style_tabsblogcarouselsecondstkaveh'
      );
      
      $this->start_controls_tab(
        'style_normal_tabblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Normal', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbuttoncolorblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Button Text Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .btn' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttoncolorblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Button Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .btn' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttonradiusblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'More Button Rounded Corners', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .btn' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Border::get_type(),
        [
          'name' => 'borderblogcarouselsecondstkaveh',
          'label' => esc_html__( 'Border', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .new-articles-blog .right .btn',
        ]
      );
      $this->add_control(
        'buttonbordersblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Border Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'condition' => [
            'borderblogcarouselsecondstkaveh!' => '',
          ],
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .btn' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->end_controls_tab();
      $this->start_controls_tab(
        'style_hove_tabblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Hover', 'kavehTheme' ),
        ]
      );
      $this->add_control(
        'textbuttoncolorhoverblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Button Text Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .btn:hover' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttoncolorhoverblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Button Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .btn:hover' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'buttonradiushoverblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'More Button Rounded Corners', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .btn:hover' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
          ],
        ]
      );
      $this->add_group_control(
        \Elementor\Group_Control_Border::get_type(),
        [
          'name' => 'borderhoverblogcarouselsecondstkaveh',
          'label' => esc_html__( 'Border', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .new-articles-blog .right .btn:hover',
        ]
      );
      $this->add_control(
        'buttonbordershoverblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Border Width', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'condition' => [
            'borderhoverblogcarouselsecondstkaveh!' => '',
          ],
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .btn:hover' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}} !important;',
          ],
        ]
      );
      $this->end_controls_tab();
      $this->end_controls_tabs();
      $this->add_group_control(
        \Elementor\Group_Control_Box_Shadow::get_type(),
        [
          'name' => 'box_shadowblogcarouselsecondstkavehh',
          'label' => esc_html__( 'Button Shadow', 'kavehTheme' ),
          'selector' => '{{WRAPPER}} .new-articles-blog .right .btn',
        ]
      );
      $this->add_control(
        'hr1blogcarouselsecondstkaveh',
        [
          'type' => \Elementor\Controls_Manager::DIVIDER,
        ]
      );
      $this->add_control(
        'buttonpaddingblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Inner Spacing', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::DIMENSIONS,
          'size_units' => [ 'px' ],
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog .right .btn' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
          ],
        ]
      );
      $this->end_controls_section();
      $this->start_controls_section(
        'style3_blogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Box Style', 'kavehTheme' ),
          'tab' => \Elementor\Controls_Manager::TAB_STYLE,
          'condition' => [
            'moreblogcarouselsecondstkaveh' => 'yes',
          ],
        ]
      );
      $this->add_control(
        'bgcolorblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Box Background Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .new-articles-blog' => 'background-color: {{VALUE}}',
          ],
        ]
      ); 
      $this->add_control(
        'titlepostcolorblogcarouselsecondstkaveh',
        [
          'label' => esc_html__( 'Post Title Color', 'kavehTheme' ),
          'type' => \Elementor\Controls_Manager::COLOR,
          'selectors' => [
            '{{WRAPPER}} .article-six h2 a' => 'color: {{VALUE}}',
          ],
        ]
      ); 
      $this->end_controls_section();

        }


  protected function render(){
    $settings = $this->get_settings_for_display();
    $clsid = $this->get_id();
    ?>
    <div class="new-articles-blog">
      <div class="container">
        <div class="new-article-blog-wrapper d-flex position-relative flex-column flex-lg-row">
          <!-- Start Title -->
          <div class="right text-white mb-4 mb-lg-0">
            <<?php echo  esc_attr($settings['tagheading1blogcarouselsecondstkaveh']); ?> class="sup-title"><?php echo  esc_html($settings['title1blogcarouselsecondstkaveh']); ?></<?php echo  esc_attr($settings['tagheading1blogcarouselsecondstkaveh']); ?>>
            <<?php echo  esc_attr($settings['tagheading2blogcarouselsecondstkaveh']); ?> class="title position-relative"><?php echo  esc_html($settings['title2blogcarouselsecondstkaveh']); ?></<?php echo  esc_attr($settings['tagheading2blogcarouselsecondstkaveh']); ?>>
            <a href="<?php echo  esc_url($settings['linktitle3blogcarouselsecondstkaveh']); ?>" class="read-more"><?php echo  esc_html($settings['title3blogcarouselsecondstkaveh']); ?></a>
            <?php if("yes"===$settings['moreblogcarouselsecondstkaveh']){?>
            <a href="<?php echo  esc_html($settings['buttonlinkblogcarouselsecondstkaveh']); ?>"><div class="btn btn-light d-block"> <?php echo  esc_html($settings['buttonblogcarouselsecondstkaveh']); ?></div></a>
            <?php } ?>
          </div>
          <!-- End Title -->
          <!-- Start Items -->
          <div class="left">
            <div class="swiper swiper-new-articles-blog overflow-hidden" data-swiper='{"loop":true,"navigation":{"nextEl":".swiper-button-next","prevEl":".swiper-button-prev"},"breakpoints":{"320":{"slidesPerView":1,"spaceBetween":4},"576":{"slidesPerView":2,"spaceBetween":8},"768":{"slidesPerView":2,"spaceBetween":12},"992":{"slidesPerView":2,"spaceBetween":30}}}'>
            <div class="swiper-wrapper">
                <?php
                // Define your custom query arguments
                $query_args = array(
                  'post_type' => 'post',
                  'posts_per_page' => $settings['productnumberblogcarouselsecondstkaveh'],
                  'order' => 'desc',
                  'orderby' => 'date',
                  'post_status' => 'publish',
                  'tax_query' => array(
                  array(
                      'taxonomy' => 'category',
                      'field'    => 'term_id',
                      'terms'    => $settings['catblogenfhess'],
                      ),
                  ),
                );
                // Get the cached query results
                $cached_query = KavehCustomQuery::get_cached_query($query_args);
                if ($cached_query->have_posts()) :
                    while ($cached_query->have_posts()) : $cached_query->the_post();
                    ?>
                    <div class="swiper-slide">
                        <?php get_template_part("template-part/blog-cart-six"); ?>
                    </div>
                    <?php
                    endwhile;
                    wp_reset_postdata();
                else :
                    echo 'No posts found.';
                endif;
                ?>
            </div>
              <div class="swiper-button-next"></div>
              <div class="swiper-button-prev"></div>
            </div>
          </div>
          <!-- End Items -->
        </div>
      </div>
    </div> 
    <style>
        <?php echo '.elementor-element-' . $clsid . ''; ?> .article-six figure::after {
            -webkit-background-size: cover !important;
            -moz-background-size: cover !important;
            -o-background-size: cover !important;
            background-size: cover !important;
            object-fit: cover !important;
        }
    </style>
    

    <?php
  }


}
