<?php 
/**
 * Template part for displaying Slider Section
 *
 * @package prime-fitness-gym
 */

$prime_fitness_gym_data_slick_speed = prime_fitness_gym_get_option('data_slick_speed');
$prime_fitness_gym_data_slick_infinite = prime_fitness_gym_get_option('data_slick_infinite');
$prime_fitness_gym_data_slick_dots = prime_fitness_gym_get_option('data_slick_dots');
$prime_fitness_gym_data_slick_autoplay = prime_fitness_gym_get_option('data_slick_autoplay');
$prime_fitness_gym_data_slick_draggable = prime_fitness_gym_get_option('data_slick_draggable');
$prime_fitness_gym_data_slick_fade = prime_fitness_gym_get_option('data_slick_fade');
$prime_fitness_gym_featured_slider_content_type = prime_fitness_gym_get_option('featured_slider_content_type');
$prime_fitness_gym_number_of_featured_slider_items = prime_fitness_gym_get_option('number_of_featured_slider_items');
// $slider_enable_section               = get_theme_mod('slider_enable_section', 'on');

?>
<?php if (!get_theme_mod('slider_enable_section', true)) {
    return;
} ?>

<?php
// Convert numeric options to boolean strings for slick carousel
$prime_fitness_gym_data_slick_infinite = $prime_fitness_gym_data_slick_infinite ? 'true' : 'false';
$prime_fitness_gym_data_slick_dots = $prime_fitness_gym_data_slick_dots ? 'true' : 'false';
$prime_fitness_gym_data_slick_autoplay = $prime_fitness_gym_data_slick_autoplay ? 'true' : 'false';
$prime_fitness_gym_data_slick_draggable = $prime_fitness_gym_data_slick_draggable ? 'true' : 'false';
$prime_fitness_gym_data_slick_fade = $prime_fitness_gym_data_slick_fade ? 'true' : 'false';
?>

<div id="featured-slider">
    <div class="section-content"
        data-slick='{"slidesToShow": 1, "slidesToScroll": 1, "infinite": <?php echo esc_attr($prime_fitness_gym_data_slick_infinite); ?>, "speed": <?php echo esc_attr($prime_fitness_gym_data_slick_speed); ?>, "dots": <?php echo esc_attr($prime_fitness_gym_data_slick_dots); ?>, "autoplay": <?php echo esc_attr($prime_fitness_gym_data_slick_autoplay); ?>, "draggable": <?php echo esc_attr($prime_fitness_gym_data_slick_draggable); ?>, "fade": <?php echo esc_attr($prime_fitness_gym_data_slick_fade); ?> }'>

        <?php
           $prime_fitness_gym_number_of_featured_slider_items = absint( get_theme_mod('number_of_featured_slider_items', 5) ); // Ensure the value is an integer

           // Ensure the number of posts starts from 1, and not showing any extras
           if ($prime_fitness_gym_number_of_featured_slider_items < 1) {
               $prime_fitness_gym_number_of_featured_slider_items = 1; // Ensure minimum value is 1
           }
        
           ?> <?php $prime_fitness_gym_slider_pages = array(); 
			    for ( $prime_fitness_gym_count = 1; $prime_fitness_gym_count <= 4; $prime_fitness_gym_count++ ) {
			        $prime_fitness_gym_mod = intval( get_theme_mod( 'select_post_slider'. $prime_fitness_gym_count ));
			        if ( 'page-none-selected' != $prime_fitness_gym_mod ) {
			          $prime_fitness_gym_slider_pages[] = $prime_fitness_gym_mod;
			        }
			    }
		      	if( !empty($prime_fitness_gym_slider_pages) ) :
			        $prime_fitness_gym_args = array(
			          	'post_type' => 'post',
			          	'post__in' => $prime_fitness_gym_slider_pages,
                        'posts_per_page' => $prime_fitness_gym_number_of_featured_slider_items,
			          	'orderby' => 'post__in'
			        );
		        	$prime_fitness_gym_catquery = new WP_Query( $prime_fitness_gym_args );
        
           $prime_fitness_gym_catquery_counter = 0; // Initialize counter
           while ($prime_fitness_gym_catquery->have_posts() && $prime_fitness_gym_catquery_counter < $prime_fitness_gym_number_of_featured_slider_items) : $prime_fitness_gym_catquery->the_post();
           $prime_fitness_gym_catquery_counter++;
    ?>
        <article data-post-id="<?php echo esc_attr(get_the_ID()); ?>">
            <div class="opbg">
                <div class="slide-inner slide-bg-image">
                    <div class="sliderimg">
                        <img class="d-block w-100" src="<?php echo esc_url(get_the_post_thumbnail_url()); ?>">
                    </div>
                    <div class="row d-flex align-items-center">
                        <div class="slider-inner-mainbox">
                            <?php if (get_theme_mod('featured_slider_overlayimg_enable', true)) : ?>
                            <!-- Additional content if enabled -->
                            <?php endif; ?>
                            <div class="container leftcontentbox <?php echo esc_attr(get_theme_mod('prime_fitness_gym_featured_slider_onload_effects', 'wow zoomIn')); ?>"
                                data-wow-duration="2s">

                                <div class="wrapper animated <?php echo esc_attr(get_theme_mod('prime_fitness_gym_featured_slider_onload_effects','wow Bounce In Up')); ?>"
                                    data-wow-duration="2s">
                                    <div class="slider-socialicon"><a href="#" class="me-4">
                                            <i
                                                class="fa-brands socialicon <?php echo esc_html(get_theme_mod('prime_fitness_gym_facebook_icon', __('fa-facebook-f', 'prime-fitness-gym'))) ?>"></i>
                                        </a>
                                        <a href="#" class="me-4">
                                            <i
                                                class="fa-brands socialicon <?php echo esc_html(get_theme_mod('prime_fitness_gym_instagram_icon', __('fa-instagram', 'prime-fitness-gym'))) ?>">"></i>
                                        </a>
                                        <a href="#">
                                            <i
                                                class="fa-brands socialicon <?php echo esc_html(get_theme_mod('prime_fitness_gym_twitter_icon', __('fa-x-twitter', 'prime-fitness-gym'))) ?>"></i>
                                        </a>
                                        <a href="#">
                                            <i
                                                class="fa-brands socialicon <?php echo esc_html(get_theme_mod('prime_fitness_gym_youtube_icon', __('fa-youtube', 'prime-fitness-gym'))) ?>"></i>
                                        </a>
                                    </div>
                                    <div class="entry-container d-flex">
                                        <div class="vl-entry"></div>
                                        <div class="entry-content-div">
                                            <div class="content">
                                                <h3
                                                    style="text-transform : <?php if(get_theme_mod('featured_slider_subtitle_case','None') == 'None'){ ?> none <?php } elseif(get_theme_mod('featured_slider_subtitle_case','Lowercase') == 'Lowercase'){ ?> lowercase <?php } elseif(get_theme_mod('featured_slider_subtitle_case','Capitalize') == 'Capitalize'){ ?> capitalize <?php } elseif(get_theme_mod('featured_slider_subtitle_case','Uppercase') == 'Uppercase'){ ?> uppercase <?php } ?>"><?php the_title(); ?><?php
                                                // Set a word limit, e.g., 40 words
                                                $prime_fitness_gym_content_limit = 2;                                     
                                                // Get the content and trim it
                                                echo wp_trim_words(get_the_content(), $prime_fitness_gym_content_limit,'');                                    
                                                // Optionally add a 'Read More' link
                                                // echo '<a class="readbtn mx-1" href="' . get_permalink() . '">' . __('Read More....', 'prime-fitness-gym') . '</a>';
                                            ?></h3>
                                            </div>
                                            <h2 class="entry-title"
                                                style="text-transform : <?php if(get_theme_mod('featured_slider_title_case','None') == 'None'){ ?> none <?php } elseif(get_theme_mod('featured_slider_title_case','Lowercase') == 'Lowercase'){ ?> lowercase <?php } elseif(get_theme_mod('featured_slider_title_case','Capitalize') == 'Capitalize'){ ?> capitalize <?php } elseif(get_theme_mod('featured_slider_title_case','Uppercase') == 'Uppercase'){ ?> uppercase <?php } ?>;">
                                                <?php the_title(); ?></h2>

                                            <div class="entry-content animated flipInY">
                                                <?php
                                                    $prime_fitness_gym_excerpt = prime_fitness_gym_the_excerpt( 10 );
                                                    echo wp_kses_post( wpautop( $prime_fitness_gym_excerpt ) );
                                                ?>
                                            </div><!-- .entry-content -->

                                            <div class="btn-img" style="width: max-content;">
                                                <div class="sliderbut1 animated flipInY d-flex">
                                                    <a href="#"
                                                        class="btn1 btn-custom1 rounded1"><?php echo esc_html(get_theme_mod('prime_fitness_gym_button1_text','Join Us Now')); ?></a>
                                                    <div class="button-icon"><i class="fa-solid fa-play"></i></div>
                                                </div>
                                                <?php 
                                                $prime_fitness_gym_featured_slider_posts = wp_list_pluck($prime_fitness_gym_catquery->posts, 'ID'); 
                                                ?>
                                                <div id="slider-thumbnails">
                                                    <?php
                                                        foreach ($prime_fitness_gym_featured_slider_posts as $prime_fitness_gym_post_id) :
                                                        if ($prime_fitness_gym_post_id == get_the_ID()) {
                                                            continue; // Skip the current slider post
                                                        }
                                                        $prime_fitness_gym_thumbnail = get_the_post_thumbnail_url($prime_fitness_gym_post_id, 'thumbnail');
                                                        if ($prime_fitness_gym_thumbnail) :
                                                        ?>
                                                            <img src="<?php echo esc_url($prime_fitness_gym_thumbnail); ?>"
                                                                class="thumbnail" alt="Thumbnail"
                                                                data-post-id="<?php echo esc_attr($prime_fitness_gym_post_id); ?>" />
                                                    <?php 
                                                endif;
                                                endforeach;
                                                ?>
                                                </div>
                                            </div>
                                        </div>
                                    </div><!-- .entry-container -->
                                </div><!-- .wrapper -->
                            </div><!-- .leftcontentbox -->
                        </div><!-- .slider-inner-mainbox -->
                    </div><!-- .row -->
                </div><!-- .slide-inner -->
            </div><!-- .opbg -->
        </article>
        <?php endwhile; ?>
        <?php endif;?>
        <?php wp_reset_postdata(); ?>
    </div><!-- .section-content -->
</div>