<?php
/**
 * Template part for displaying slider section
 *
 * @package Medical Medicare
 * @subpackage medical_medicare
 */

?>
<?php $medical_medicare_static_image = get_stylesheet_directory_uri() . '/assets/images/slider.png'; ?>
<?php if ( get_theme_mod( 'online_pharmacy_slider_arrows', true) != '' ) : ?>

<section id="slider">
  <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel"> 
    <?php 
      $online_pharmacy_slide_pages = array();
      for ( $online_pharmacy_count = 1; $online_pharmacy_count <= 4; $online_pharmacy_count++ ) {
        $online_pharmacy_mod = intval( get_theme_mod( 'online_pharmacy_slider_page' . $online_pharmacy_count ));
        if ( 'page-none-selected' != $online_pharmacy_mod ) {
          $online_pharmacy_slide_pages[] = $online_pharmacy_mod;
        }
      }
      if ( !empty($online_pharmacy_slide_pages) ) :
        $online_pharmacy_args = array(
          'post_type' => 'page',
          'post__in' => $online_pharmacy_slide_pages,
          'orderby' => 'post__in'
        );
        $online_pharmacy_query = new WP_Query( $online_pharmacy_args );
        if ( $online_pharmacy_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="carousel-inner" role="listbox">
      <?php while ( $online_pharmacy_query->have_posts() ) : $online_pharmacy_query->the_post(); ?>
        <div class="carousel-item <?php echo ($i == 1) ? 'active' : ''; ?>">
          <?php if ( has_post_thumbnail() ) { ?>
            <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title(); ?>"/>
          <?php } else { ?>
            <img src="<?php echo esc_url($medical_medicare_static_image); ?>" alt="<?php esc_attr_e('Default Image', 'medical-medicare'); ?>"/>
          <?php } ?>
          <div class="carousel-caption">
            <div class="inner_carousel">
              <?php if (get_theme_mod('online_pharmacy_show_slider_title', true)) : ?>
                <h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
              <?php endif; ?>
              <?php if (get_theme_mod('online_pharmacy_show_slider_content', true)) : ?>
                <p><?php $online_pharmacy_excerpt = get_the_excerpt(); echo esc_html( online_pharmacy_string_limit_words( $online_pharmacy_excerpt, esc_attr(get_theme_mod('online_pharmacy_slider_excerpt_length','20')))); ?></p>
              <?php endif; ?>
              <div class="more-btn">
                <a href="<?php the_permalink(); ?>"><?php esc_html_e('CHECK OUT','medical-medicare'); ?></a>
              </div>
            </div>
          </div>
        </div>
      <?php $i++; endwhile; wp_reset_postdata(); ?>
    </div>
    <?php else : ?>
      <div class="no-postfound"><?php esc_html_e('No posts found', 'medical-medicare'); ?></div>
    <?php endif; endif; ?>
    <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
      <i class="fas fa-angle-left" aria-hidden="true"></i>
      <span class="screen-reader-text"><?php echo esc_html('Previous', 'medical-medicare'); ?></span>
    </button>
    <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
      <i class="fas fa-angle-right" aria-hidden="true"></i>
      <span class="screen-reader-text"><?php echo esc_html('Next', 'medical-medicare'); ?></span>
    </button>
  </div>
  <div class="clearfix"></div>
</section> 

<?php endif; ?>
