<?php
// Fetch the slider setting from the Customizer
$expert_videographer_slider = get_theme_mod('expert_videographer_slider_setting', true);

// Check if the slider is enabled
if ($expert_videographer_slider == '1') : ?>
<section id="slider-section" class="slider-area">
    <div class="slider-content">
        <div id="owl-carousel" class="owl-carousel owl-theme">
            <?php

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

            // If pages were selected, run the query
            if (!empty($expert_videographer_pages)) :
                $args = array(
                    'post_type' => 'page',
                    'post__in' => $expert_videographer_pages,
                    'orderby' => 'post__in'
                );
                $query = new WP_Query($args);

                // If pages were found, display them
                if ($query->have_posts()) :
                    while ($query->have_posts()) : $query->the_post(); ?>
                            <div class="row">
                                <div class="col-xl-7 col-lg-6 col-md-5 align-self-center">
                                    <div class="carousel-caption">
                                        <div class="inner_carousel pe-lg-5 wow fadeInUp" data-wow-delay="0.5s">
                                            <?php
                                            // Fetch slider text from Customizer
                                            $expert_videographer_slider_text = get_theme_mod('expert_videographer_slider_text');
                                            if (!empty($expert_videographer_slider_text)) { ?>
                                                <p class="mb-2 slider-top-text"><?php echo esc_html($expert_videographer_slider_text); ?></p>
                                            <?php } ?>

                                            <!-- Display the page title -->
                                            <h1 class="mb-3">
                                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                            </h1>

                                            <div class="slider-mainbtn mt-md-4 mt-3 mb-3">
                                                <!-- First button -->
                                                <span class="slide-btn1">
                                                    <a href="<?php the_permalink(); ?>" class="btn-text me-md-3 mb-2">
                                                        <?php echo esc_html__('Info More', 'expert-videographer'); ?>
                                                    </a>
                                                </span>

                                                <!-- Second button  -->
                                                <span class="slide-btn2">
                                                    <?php
                                                    $expert_videographer_slider_btn_text = get_theme_mod('expert_videographer_slider_btn_text', 'Info More');
                                                    $expert_videographer_slider_btn_link = get_theme_mod('expert_videographer_slider_btn_link');

                                                    if (!empty($expert_videographer_slider_btn_text) || !empty($expert_videographer_slider_btn_link)) { ?>
                                                        <a href="<?php echo esc_url($expert_videographer_slider_btn_link); ?>" class="btn-text">
                                                            <?php echo esc_html($expert_videographer_slider_btn_text); ?>
                                                        </a>
                                                    <?php } ?>
                                                </span>
                                            </div>

                                            <!-- Customer image and award section -->
                                            <div class="award-box mt-lg-4 mt-3 text-start d-flex align-items-lg-center wow bounceIn" data-wow-delay="0.5s">
                                                <?php if (get_theme_mod('expert_videographer_customer_img') || get_theme_mod('expert_videographer_award_name')) : ?>
                                                <div class="first-content-award me-3 mb-3">
                                                    <?php
                                                    // Display customer image from Customizer or show placeholder
                                                    $expert_videographer_customer_img = get_theme_mod('expert_videographer_customer_img');
                                                    if (!empty($expert_videographer_customer_img)) {
                                                        echo '<img src="' . esc_url($expert_videographer_customer_img) . '" alt="' . esc_attr__('Customer Image', 'expert-videographer') . '" />';
                                                    } else {
                                                        echo '<div class="no-customer-img"></div>';
                                                    }
                                                    ?>
                                                    <div class="main-award ms-2">
                                                        <!-- Display award name from Customizer -->
                                                        <div class="mb-1 text-capitalize customer-name"><?php esc_html_e('Best Videographer of the Year', 'expert-videographer'); ?></div>
                                                        <?php if ($expert_videographer_award_name = get_theme_mod('expert_videographer_award_name')) : ?>
                                                            <p class="annual-text">
                                                                <?php echo esc_html($expert_videographer_award_name); ?>
                                                            </p>
                                                        <?php endif; ?>
                                                    </div>
                                                </div>
                                                 <?php endif; ?>

                                                <!-- Social media icons -->
                                                <div class="social-media mb-3">
                                                    <?php if ($expert_videographer_facebook_url = get_theme_mod('expert_videographer_facebook_url')) : ?>
                                                        <a target="_blank" rel="noopener noreferrer" href="<?php echo esc_url($expert_videographer_facebook_url); ?>">
                                                            <i class="fab fa-facebook-f me-2"></i>
                                                        </a>
                                                    <?php endif; ?>
                                                    <?php if ($expert_videographer_twitter_url = get_theme_mod('expert_videographer_twitter_url')) : ?>
                                                        <a target="_blank" rel="noopener noreferrer" href="<?php echo esc_url($expert_videographer_twitter_url); ?>">
                                                            <i class="fab fa-twitter me-2"></i>
                                                        </a>
                                                    <?php endif; ?>
                                                    <?php if ($expert_videographer_instagram_url = get_theme_mod('expert_videographer_instagram_url')) : ?>
                                                        <a target="_blank" rel="noopener noreferrer" href="<?php echo esc_url($expert_videographer_instagram_url); ?>">
                                                            <i class="fab fa-instagram-square me-2"></i></i>
                                                        </a>
                                                    <?php endif; ?>
                                                    <?php if ($expert_videographer_youtube_url = get_theme_mod('expert_videographer_youtube_url')) : ?>
                                                        <a target="_blank" rel="noopener noreferrer" href="<?php echo esc_url($expert_videographer_youtube_url); ?>">
                                                            <i class="fab fa-youtube me-2"></i>
                                                        </a>
                                                    <?php endif; ?>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <!-- Slider image section -->
                                <div class="col-xl-5 col-lg-6 col-md-7 slider-img-col position-relative">
                                    <div class="sliderimg">
                                        <?php if (has_post_thumbnail()) { ?>
                                            <img src="<?php the_post_thumbnail_url('full'); ?>" alt="<?php the_title_attribute(); ?>" />
                                        <?php } else { ?>
                                            <div class="slider-color-box"></div>
                                        <?php } ?>
                                    </div>
                                </div>
                            </div>
                    <?php endwhile;
                    wp_reset_postdata();  // Reset post data after the loop
                else : ?>
                    <div class="no-postfound"></div>
                <?php endif;
            endif; ?>
        </div>
    </div>
</section>
<?php endif; ?>