<?php
/**
 * Template part for displaying slider section
 *
 * @package Fitness Supplement Store
 * @subpackage fitness_supplement_store
 */

?>
<?php $fitness_supplement_store_static_image= get_stylesheet_directory_uri() . '/assets/images/slider-img.png'; ?>
<?php if( get_theme_mod( 'fitness_supplement_store_slider_arrows', true) != '') { ?>
  <section id="slider" class="mb-3">
  <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
    <?php $fitness_supplement_store_slide_pages = array();
      for ( $count = 1; $count <= 4; $count++ ) {
        $mod = intval( get_theme_mod( 'fitness_supplement_store_slider_page' . $count ));
        if ( 'page-none-selected' != $mod ) {
          $fitness_supplement_store_slide_pages[] = $mod;
        }
      }
      if( !empty($fitness_supplement_store_slide_pages) ) :
        $fitness_supplement_store_args = array(
          'post_type' => 'page',
          'post__in' => $fitness_supplement_store_slide_pages,
          'orderby' => 'post__in'
        );
        $fitness_supplement_store_query = new WP_Query( $fitness_supplement_store_args );
        if ( $fitness_supplement_store_query->have_posts() ) :
          $i = 1;
    ?>
    <div class="carousel-inner" role="listbox">
      <?php  while ( $fitness_supplement_store_query->have_posts() ) : $fitness_supplement_store_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="'.$fitness_supplement_store_static_image.'">'); } ?>
          <div class="carousel-caption">
            <div class="inner_carousel">
              <div class="slider-text">
                <?php if( get_theme_mod('fitness_supplement_store_slider_title') != ''){ ?>
                  <p class="slider-top text-uppercase mb-1"><?php echo esc_html(get_theme_mod('fitness_supplement_store_slider_title')); ?></p>
                <?php }?>
                <?php if (get_theme_mod('fitness_supplement_store_show_slider_title', true)) : ?>
                  <h1>
                    <a href="href=<?php the_permalink(); ?>" class="text-uppercase">
                        <?php 
                          $title = get_the_title();
                          $words = explode(' ', $title);
                          $last_word_index = count($words) - 1; 
                          $last_word = $words[$last_word_index]; 
                          unset($words[$last_word_index]); 
                          $remaining_words = implode(' ', $words);
                          echo esc_html($remaining_words); 
                          echo ' <span class="highlight">' . esc_html($last_word) . '</span>'; 
                        ?>
                      </a>
                  </h1>
                <?php endif; ?>
              </div>
              <div class="more-btn mt-3">
                <a href="<?php the_permalink(); ?>"><?php esc_html_e('SHOP NOW','fitness-supplement-store'); ?></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-chevron-left"></i></span>
        <span class="screen-reader-text"><?php esc_html_e('Previous','fitness-supplement-store'); ?></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-chevron-right"></i></span>
        <span class="screen-reader-text"><?php esc_html_e('Next','fitness-supplement-store'); ?></span>
      </a>
  </div>
  <div class="clearfix"></div>
</section>

<?php } ?>


