<?php 
$expert_fitness_trainer_slider = get_theme_mod('expert_fitness_trainer_slider_setting', true);

if ($expert_fitness_trainer_slider == '1') :
?>

<section id="slider">
    <div id="owl-carousel" class="sliderbox owl-carousel">
        <?php

        $expert_fitness_trainer_slide_pages = array();
        for ($expert_fitness_trainer_count = 1; $expert_fitness_trainer_count <= 3; $expert_fitness_trainer_count++) {
            $expert_fitness_trainer_mod = intval(get_theme_mod('expert_fitness_trainer_slider_page' . $expert_fitness_trainer_count));
        
            // Check that the value is valid and not the placeholder value 'page-none-selected'
            if ('page-none-selected' !== $expert_fitness_trainer_mod && $expert_fitness_trainer_mod > 0) {
                $expert_fitness_trainer_slide_pages[] = $expert_fitness_trainer_mod;
            }
        }

        // If no pages are selected, fall back to the "slider-page"
        if (empty($expert_fitness_trainer_slide_pages) && $expert_fitness_trainer_default_slider_page > 0) {
            $expert_fitness_trainer_slide_pages[] = $expert_fitness_trainer_default_slider_page;
        }

        if (!empty($expert_fitness_trainer_slide_pages)) :
            $expert_fitness_trainer_args = array(
                'post_type' => 'page',
                'post__in' => $expert_fitness_trainer_slide_pages,
                'orderby' => 'post__in'
            );
            $expert_fitness_trainer_query = new WP_Query($expert_fitness_trainer_args);
            if ($expert_fitness_trainer_query->have_posts()) :
                while ($expert_fitness_trainer_query->have_posts()) : $expert_fitness_trainer_query->the_post(); ?>
                    <div class="item">
                        <?php if (has_post_thumbnail()) { ?>
                            <img src="<?php echo esc_url(get_the_post_thumbnail_url(get_the_ID(), 'full')); ?>" alt="<?php echo esc_attr(get_the_title()); ?>" />
                        <?php } else { ?>
                            <div class="slider-color-box"></div>
                        <?php } ?>

                        <div class="container">
                            <div class="carousel-caption">
                                <div class="inner_carousel wow zoomInUp" data-wow-delay="0.5s">
                                    <?php if (get_theme_mod('expert_fitness_trainer_slider_short_heading') != '') { ?>
                                        <p class="slidetop-text mb-3"><?php echo esc_html(get_theme_mod('expert_fitness_trainer_slider_short_heading', '')); ?></p>
                                    <?php } ?>
                                    <h1 class="mb-2"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                                    <p class="mb-2"><?php echo esc_html(wp_trim_words(get_the_content(), 45)); ?></p>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endwhile;
                wp_reset_postdata(); ?>
            <?php else : ?>
                <div class="no-postfound"><?php esc_html_e('No posts found.', 'expert-fitness-trainer'); ?></div>
            <?php endif;
        endif; ?>
    </div>

    <div class="rating-col wow fadeInUp" data-wow-delay="0.5s">
        <div class="row rating-box position-relative">
            <div class="col-lg-5 col-md-5 col-4 text-end align-self-center">
                <?php 
                $expert_fitness_trainer_selected_category = get_theme_mod('expert_fitness_trainer_about_catData', 'uncategorized');
                if ($expert_fitness_trainer_selected_category != 'select') { ?>
                    <span class="abt-cat text-end">
                        <div class="owl-carousel owl-theme m-0">
                            <?php
                            $expert_fitness_trainer_abtpage_query = new WP_Query(array(
                                'category_name' => esc_attr($expert_fitness_trainer_selected_category),
                                'posts_per_page' => -1,
                            ));
                            if ($expert_fitness_trainer_abtpage_query->have_posts()) :
                                while ($expert_fitness_trainer_abtpage_query->have_posts()) : $expert_fitness_trainer_abtpage_query->the_post(); ?>
                                    <span class="abt-imagebox">
                                        <?php if (has_post_thumbnail()) { ?>
                                            <img src="<?php echo esc_url(get_the_post_thumbnail_url()); ?>" alt="<?php echo esc_attr(get_the_title()); ?>" />
                                        <?php } else { ?>
                                            <!-- <div class="abt-img-color"></div> -->
                                            <img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/trainers.png'); ?>" alt="<?php echo esc_attr(get_the_title()); ?>" />
                                        <?php } ?>
                                    </span>
                                <?php endwhile;
                                wp_reset_postdata();
                            else : ?>
                                <p><?php esc_html_e('No posts found in this category.', 'expert-fitness-trainer'); ?></p>
                            <?php endif; ?>
                        </div>
                    </span>
                <?php } ?>
            </div>

            <div class="col-lg-7 col-md-7 col-8 px-0 enroll-box text-end align-self-center">
                <span class="customizer-rating">
                    <?php 
                    $expert_fitness_trainer_student_count = get_theme_mod('expert_fitness_trainer_student_count', '');

                    if (!empty($expert_fitness_trainer_student_count)) { 
                        echo esc_html__('Join Over', 'expert-fitness-trainer') . ' ' . esc_html($expert_fitness_trainer_student_count) . ' ' . esc_html__('Students', 'expert-fitness-trainer');
                    } 
                    ?>
                </span>
                <span class="more-btn ms-2">
                    <?php 
                    $expert_fitness_trainer_slider_btn_text = get_theme_mod('expert_fitness_trainer_slider_btn_text','ENROLL NOW');
                    $expert_fitness_trainer_slider_btn_link = get_theme_mod('expert_fitness_trainer_slider_btn_link','');
                    if (!empty($expert_fitness_trainer_slider_btn_text) || !empty($expert_fitness_trainer_slider_btn_link)) { ?>
                        <a target="_blank" class="me-lg-2 text-capitalize slider-btn1" href="<?php echo esc_url($expert_fitness_trainer_slider_btn_link); ?>">
                            <?php echo esc_html($expert_fitness_trainer_slider_btn_text ? $expert_fitness_trainer_slider_btn_text : __('ENROLL NOW', 'expert-fitness-trainer')); ?><i class="fas fa-arrow-right ms-1"></i>
                        </a>
                    <?php } ?>
                </span>
            </div>
        </div>
    </div>
</section>
<?php endif; ?>