<?php
/**
 * Template part for displaying slider section
 *
 * @package Business Meetup Conference
 * @subpackage business_meetup_conference
 */

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

<section id="slider">
  <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
    <?php $business_meetup_conference_slide_pages = array();
      for ( $business_meetup_conference_count = 1; $business_meetup_conference_count <= 4; $business_meetup_conference_count++ ) {
        $business_meetup_conference_mod = intval( get_theme_mod( 'business_meetup_conference_slider_page' . $business_meetup_conference_count ));
        if ( 'page-none-selected' != $business_meetup_conference_mod ) {
          $business_meetup_conference_slide_pages[] = $business_meetup_conference_mod;
        }
      }
      if( !empty($business_meetup_conference_slide_pages) ) :
        $business_meetup_conference_args = array(
          'post_type' => 'page',
          'post__in' => $business_meetup_conference_slide_pages,
          'orderby' => 'post__in'
        );
        $business_meetup_conference_query = new WP_Query( $business_meetup_conference_args );
        if ( $business_meetup_conference_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="carousel-inner" role="listbox">
      <?php  while ( $business_meetup_conference_query->have_posts() ) : $business_meetup_conference_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 {echo ('<img src="'.$business_meetup_conference_static_image.'">'); } ?>
          <div class="carousel-caption">
            <div class="inner_carousel">
              <?php if( get_theme_mod( 'business_meetup_conference_slider_heading' ) != '' ) { ?>
                <p class="slider-top"><?php echo esc_html( get_theme_mod( 'business_meetup_conference_slider_heading','' ) ); ?></p>
              <?php } ?>
              <?php if (get_theme_mod('business_meetup_conference_show_slider_title', true)) : ?>
                <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
              <?php endif; ?>
              <?php if (get_theme_mod('business_meetup_conference_show_slider_content', true)) : ?>
                  <p><?php $business_meetup_conference_excerpt = get_the_excerpt(); echo esc_html( business_meetup_conference_string_limit_words( $business_meetup_conference_excerpt, esc_attr(get_theme_mod('business_meetup_conference_slider_excerpt_length','20')))); ?></p>
              <?php endif; ?>  
                <div class="more-btn col-12">
                  <a class="register-btn" href="<?php the_permalink(); ?>"><?php esc_html_e('Register Now','business-meetup-conference'); ?></a>
                  <?php if( get_theme_mod( 'business_meetup_conference_video_button_link'.$i ) != '') { ?>
                      <button class="popup-btn"><i class="fas fa-play"></i></button><span class="watch-text"><?php esc_html_e('Watch Now','business-meetup-conference'); ?></span>
                      <div class="video-popup col-12">
                    <div class="popup-bg"></div>
                      <div class="popup-content">
                        <iframe src="<?php echo esc_url( get_theme_mod( 'business_meetup_conference_video_button_link' .$i,'' ) ); ?>" class="video"></iframe>
                        <button class="close-btn">close</button>
                      </div>
                  </div>
                  <?php } ?>
                </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','business-meetup-conference'); ?></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','business-meetup-conference'); ?></span>
    </a> 
  </div>
  <div class="clearfix"></div>
</section>

<?php } ?>
