<?php 
$automotive_services_slider = get_theme_mod('automotive_services_slider_setting', false);

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

<section id="slider">
    <?php 
  // Get side text for the slider
  $automotive_services_side_text = get_theme_mod( 'automotive_services_slider_side_text', 'WELCOME!' ); 
  if ( ! empty( $automotive_services_side_text ) ) : ?>
    <p class="welcome-text m-0"><?php echo esc_html( $automotive_services_side_text ); ?></p>
  <?php endif; ?>
    <div id="owl-carousel" class="owl-carousel">
        <?php
        $automotive_services_slide_pages = array();
        for ($automotive_services_count = 1; $automotive_services_count <= 3; $automotive_services_count++) {
            $automotive_services_mod = intval(get_theme_mod('automotive_services_slider_page' . $automotive_services_count));
        
            // Check that the value is valid and not the placeholder value 'page-none-selected'
            if ('page-none-selected' !== $automotive_services_mod && $automotive_services_mod > 0) {
                $automotive_services_slide_pages[] = $automotive_services_mod;
            }
        }
        

        if (!empty($automotive_services_slide_pages)) :
            $automotive_services_args = array(
                'post_type' => 'page',
                'post__in' => $automotive_services_slide_pages,
                'orderby' => 'post__in'
            );
            $automotive_services_query = new WP_Query($automotive_services_args);
            if ($automotive_services_query->have_posts()) :
                while ($automotive_services_query->have_posts()) : $automotive_services_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 fadeInRight" data-wow-delay="0.5s">
                                    <?php if (get_theme_mod('automotive_services_slider_short_heading') != '') { ?>
                                        <p class="slidetop-text mb-1"><?php echo esc_html(get_theme_mod('automotive_services_slider_short_heading', '')); ?></p>
                                    <?php } ?>
                                    <h1 class="custom-title mb-2">
                                      <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                    </h1>
                                    <p class="mb-2 slider-content"><?php echo esc_html(wp_trim_words(get_the_content(), 25)); ?></p>
                                    <div class="more-btn mt-3">
                                        <?php 
                                        $automotive_services_btn_text = get_theme_mod('automotive_services_slider_btn_text', __('Get Started', 'automotive-services'));
                                        $automotive_services_btn_link = get_theme_mod('automotive_services_slider_btn_link');
                                        
                                        if ($automotive_services_btn_text || $automotive_services_btn_link) { ?>
                                            <a target="_blank" class="text-capitalize slider-btn1" href="<?php echo esc_url($automotive_services_btn_link ? $automotive_services_btn_link : get_permalink()); ?>">
                                                <?php echo esc_html($automotive_services_btn_text); ?>
                                            </a>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endwhile;
                wp_reset_postdata(); ?>
            <?php else : ?>
                <div class="no-postfound"></div>
            <?php endif;
        endif; ?>
    </div>
</section>
<?php endif; ?>