<?php
/**
 * Template part for displaying slider section
 *
 * @package Conference Event Planner
 * @subpackage conference_event_planner
 */

?>

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

<section id="slider">
  <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
    <?php $conference_event_planner_slide_pages = array();
      for ( $conference_event_planner_count = 1; $conference_event_planner_count <= 4; $conference_event_planner_count++ ) {
        $conference_event_planner_mod = intval( get_theme_mod( 'conference_event_planner_slider_page' . $conference_event_planner_count ));
        if ( 'page-none-selected' != $conference_event_planner_mod ) {
          $conference_event_planner_slide_pages[] = $conference_event_planner_mod;
        }
      }
      if( !empty($conference_event_planner_slide_pages) ) :
        $conference_event_planner_args = array(
          'post_type' => 'page',
          'post__in' => $conference_event_planner_slide_pages,
          'orderby' => 'post__in'
        );
        $conference_event_planner_query = new WP_Query( $conference_event_planner_args );
        if ( $conference_event_planner_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="carousel-inner" role="listbox">
      <?php  while ( $conference_event_planner_query->have_posts() ) : $conference_event_planner_query->the_post(); ?>
        <div <?php if($i == 1){echo 'class="carousel-item active"';} else{ echo 'class="carousel-item"';}?>>
          <?php if(has_post_thumbnail()){ ?>
            <img src="<?php the_post_thumbnail_url('full'); ?>"/> <?php 
          }else { ?>
            <img src="<?php echo esc_url($conference_event_planner_static_image); ?>">
          <?php } ?>
          <div class="carousel-caption">
            <div class="inner_carousel">
              <?php if (get_theme_mod('conference_event_planner_show_slider_title', true)) : ?>
                <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
              <?php endif; ?>
              <?php if (get_theme_mod('conference_event_planner_show_slider_content', true)) : ?>
                <p><?php $conference_event_planner_excerpt = get_the_excerpt(); echo esc_html( conference_event_planner_string_limit_words( $conference_event_planner_excerpt, esc_attr(get_theme_mod('conference_event_planner_slider_excerpt_length','15')))); ?></p> 
              <?php endif; ?>
                <div class="more-btn mt-3">
                <a href="<?php the_permalink(); ?>"><?php esc_html_e('Get Started','conference-event-planner'); ?></a>
                <a class="slider-video ms-3" href="<?php echo esc_url( get_theme_mod('conference_event_planner_slider_video') ); ?>" target="_blank"><i class="fas fa-play me-3"></i><?php esc_html_e('Watch Video','conference-event-planner'); ?></a>
              </div>
            </div>
          </div>
        </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','conference-event-planner'); ?></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','conference-event-planner'); ?></span>
    </a> 
  </div>
  <div class="clearfix"></div>
</section>

<?php } ?>
