<?php
/**
 * Template part for displaying slider section
 *
 * @package Kindergarten Playgroup
 * @subpackage kindergarten_playgroup
 */

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

<section id="slider">
  <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
    <?php $kindergarten_playgroup_slide_pages = array();
      for ( $kindergarten_playgroup_count = 1; $kindergarten_playgroup_count <= 3; $kindergarten_playgroup_count++ ) {
        $kindergarten_playgroup_mod = intval( get_theme_mod( 'kindergarten_playgroup_slider_page' . $kindergarten_playgroup_count ));
        if ( 'page-none-selected' != $kindergarten_playgroup_mod ) {
          $kindergarten_playgroup_slide_pages[] = $kindergarten_playgroup_mod;
        }
      }
      if( !empty($kindergarten_playgroup_slide_pages) ) :
        $kindergarten_playgroup_args = array(
          'post_type' => 'page',
          'post__in' => $kindergarten_playgroup_slide_pages,
          'orderby' => 'post__in'
        );
        $kindergarten_playgroup_query = new WP_Query( $kindergarten_playgroup_args );
        if ( $kindergarten_playgroup_query->have_posts() ) :
          $kindergarten_playgroup_i = 1;
    ?>
    <div class="carousel-inner" role="listbox">
      <?php  while ( $kindergarten_playgroup_query->have_posts() ) : $kindergarten_playgroup_query->the_post(); ?>
        <div <?php if($kindergarten_playgroup_i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
         <?php if(has_post_thumbnail()){ ?>
            <img src="<?php echo (the_post_thumbnail_url('full')); ?>"/>
            <?php }else {echo ('<img src="'.$kindergarten_playgroup_static_image.'">'); } ?>
          <div class="carousel-caption">
            <div class="inner_carousel">
              <?php if( get_theme_mod( 'kindergarten_playgroup_slider_short_heading' ) != '' ) { ?>
                <p class="slider-top"><?php echo esc_html( get_theme_mod( 'kindergarten_playgroup_slider_short_heading','' ) ); ?></p>
              <?php } ?>
              <?php if (get_theme_mod('kindergarten_playgroup_show_slider_title', true)) : ?>
                <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
              <?php endif; ?>
              <?php if (get_theme_mod('kindergarten_playgroup_show_slider_content', true)) : ?>
                  <p><?php $kindergarten_playgroup_excerpt = get_the_excerpt(); echo esc_html( kindergarten_playgroup_string_limit_words( $kindergarten_playgroup_excerpt, esc_attr(get_theme_mod('kindergarten_playgroup_slider_excerpt_length','15')))); ?></p>
              <?php endif; ?>            
              <div class="more-btn">
                <a href="<?php the_permalink(); ?>"><?php esc_html_e('Book Appointment','kindergarten-playgroup'); ?></a>
              </div>          
            </div>
          </div>
        </div>
      <?php $kindergarten_playgroup_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','kindergarten-playgroup'); ?></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','kindergarten-playgroup'); ?></span>
    </a> 
  </div>
  <div class="clearfix"></div>
</section>

<?php } ?>
