<?php 
$expert_digital_agency_slider = get_theme_mod('expert_digital_agency_slider_setting', true);

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

<section id="slider-section" class="slider-area">
  <div class="container slider-content">
    <div id="owl-carousel" class="owl-carousel owl-theme">
        <?php
        $expert_digital_agency_pages = array();
        for ($expert_digital_agency_count = 1; $expert_digital_agency_count <= 3; $expert_digital_agency_count++) {
            $expert_digital_agency_mod = intval(get_theme_mod('expert_digital_agency_slider' . $expert_digital_agency_count));
        
            // Check that the value is valid and not the placeholder value 'page-none-selected'
            if ('page-none-selected' !== $expert_digital_agency_mod && $expert_digital_agency_mod > 0) {
                $expert_digital_agency_pages[] = $expert_digital_agency_mod;
            }
        }
        
        if (!empty($expert_digital_agency_pages)) :
            $expert_digital_agency_args = array(
                'post_type' => 'page',
                'post__in' => $expert_digital_agency_pages,
                'orderby' => 'post__in'
            );
            $expert_digital_agency_query = new WP_Query($expert_digital_agency_args);
            if ($expert_digital_agency_query->have_posts()) :
                while ($expert_digital_agency_query->have_posts()) : $expert_digital_agency_query->the_post(); ?>
                    <div class="item">
                            <div class="row">
                                <div class="col-lg-6 col-md-5 col-12 align-self-center">
                                    <div class="carousel-caption">
                                        <div class="inner_carousel wow fadeInRight" data-wow-delay="0.5s">
                                            <?php
                                            $expert_digital_agency_slider_text = get_theme_mod('expert_digital_agency_slider_text');
                                            if (!empty($expert_digital_agency_slider_text)) { ?>
                                                <p class="mb-3 slider-top-text"><?php echo esc_html(apply_filters('expert_digital_agency_topheader', $expert_digital_agency_slider_text)); ?></p>
                                            <?php } ?>
                                            
                                            <h1 class="text-uppercase mb-3">
                                                <a href="<?php the_permalink(); ?>">
                                                    <?php
                                                    $expert_digital_agency_title = get_the_title();
                                                    $expert_digital_agency_words = explode(' ', $expert_digital_agency_title);
                                                    if (count($expert_digital_agency_words) >= 4) {
                                                        $expert_digital_agency_words[3] = '<span class="highlight">' . $expert_digital_agency_words[3] . '</span>';
                                                    }
                                                    $expert_digital_agency_highlighted_title = implode(' ', $expert_digital_agency_words);
                                                    echo $expert_digital_agency_highlighted_title;
                                                    ?>
                                                </a>
                                            </h1>
                                            <p><?php echo esc_html(wp_trim_words(get_the_content(), '28')); ?></p>
                                            <div class="slider-mainbtn mt-md-4 mt-3">
                                                <span class="slide-btn1">
                                                    <a href="<?php the_permalink(); ?>" class="btn-text me-md-3 mb-2">
                                                        <?php echo esc_html__('Read More', 'expert-digital-agency'); ?>
                                                    </a>
                                                </span>
                                                <span class="slide-btn2">
                                                    <?php 
                                                        $expert_digital_agency_slider_btn_text = get_theme_mod('expert_digital_agency_slider_btn_text');
                                                        $expert_digital_agency_slider_btn_link = get_theme_mod('expert_digital_agency_slider_btn_link');

                                                        if (!empty($expert_digital_agency_slider_btn_text) && !empty($expert_digital_agency_slider_btn_link)) { ?>
                                                            <a href="<?php echo esc_url($expert_digital_agency_slider_btn_link); ?>" class="btn-text">
                                                                <?php echo esc_html($expert_digital_agency_slider_btn_text); ?>
                                                            </a>
                                                    <?php } ?>
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-lg-6 col-md-7 col-12 slider-img-col d-md-flex justify-content-md-center align-self-center p-0 wow fadeInLeft" data-wow-delay="0.5s">
                                    <div class="sliderimg">
                                        <?php if (has_post_thumbnail()) { ?>
                                            <img src="<?php the_post_thumbnail_url(''); ?>"/>
                                        <?php } else { ?>
                                            <div class="slider-color-box"></div>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                    </div>
                <?php endwhile;
                wp_reset_postdata();
            else : ?>
                <div class="no-postfound"></div>
            <?php endif;
        endif; ?>
    </div>
  </div>
</section>
<?php endif; ?>
