<?php
/**
 * Template part for displaying slider section
 *
 * @package Web Graphic Designer
 * @subpackage web_graphic_designer
 */

?>
<?php $web_graphic_designer_static_image = get_stylesheet_directory_uri() . '/assets/images/slider-img.png'; ?>
<?php if( get_theme_mod( 'web_graphic_designer_slider_arrows', true) != '') { ?>

<section id="slider">
  <div class="container">
    <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
    <?php $web_graphic_designer_slide_pages = array();
      for ( $web_graphic_designer_count = 1; $web_graphic_designer_count <= 4; $web_graphic_designer_count++ ) {
        $web_graphic_designer_mod = intval( get_theme_mod( 'web_graphic_designer_slider_page' . $web_graphic_designer_count ));
        if ( 'page-none-selected' != $web_graphic_designer_mod ) {
          $web_graphic_designer_slide_pages[] = $web_graphic_designer_mod;
        }
      }
      if( !empty($web_graphic_designer_slide_pages) ) :
        $web_graphic_designer_args = array(
          'post_type' => 'page',
          'post__in' => $web_graphic_designer_slide_pages,
          'orderby' => 'post__in'
        );
        $web_graphic_designer_query = new WP_Query( $web_graphic_designer_args );
        if ( $web_graphic_designer_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="carousel-inner" role="listbox">
      <?php  while ( $web_graphic_designer_query->have_posts() ) : $web_graphic_designer_query->the_post(); ?>
        <div <?php if($i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
          <div class="carousel-caption">
            <div class="inner_carousel">
              <?php if (get_theme_mod('web_graphic_designer_show_slider_title', true)) : ?>
                <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
              <?php endif; ?>
              <?php if (get_theme_mod('web_graphic_designer_show_slider_content', true)) : ?>
                  <p><?php echo wp_trim_words( get_the_content(),15 );?></p>
              <?php endif; ?>
            </div>
          </div>
          <?php if(has_post_thumbnail()){ ?>
               <img src="<?php (the_post_thumbnail_url('full')); ?>"/> <?php }else {echo ('<img src="'.$web_graphic_designer_static_image.'">'); } ?>
        </div>
      <?php $i++; endwhile;
      wp_reset_postdata();?>
    </div>
    <?php else : ?>
        <div class="no-postfound"></div>
      <?php endif;
    endif;?>
    <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-bs-slide="prev">
      <span class="carousel-control-prev-icon" aria-hidden="true"><i class="fas fa-angle-left"></i></span>
      <span class="screen-reader-text"><?php esc_html_e('Previous','web-graphic-designer'); ?></span>
    </a>
    <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-bs-slide="next">
      <span class="carousel-control-next-icon" aria-hidden="true"><i class="fas fa-angle-right"></i></span>
      <span class="screen-reader-text"><?php esc_html_e('Next','web-graphic-designer'); ?></span>
    </a> 
  </div>
  </div>
  
  <div class="clearfix"></div>
</section>

<?php } ?>
