<?php 
$expert_construction_company_slider = get_theme_mod('expert_construction_company_slider_setting', false);

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

<section id="slider">
    <div id="owl-carousel" class="owl-carousel">
        <?php
        $expert_construction_company_slide_pages = array();
        for ($expert_construction_company_count = 1; $expert_construction_company_count <= 4; $expert_construction_company_count++) {
            $expert_construction_company_mod = intval(get_theme_mod('expert_construction_company_slider_page' . $expert_construction_company_count));
            if ('page-none-selected' !== $expert_construction_company_mod && $expert_construction_company_mod > 0) {
                $expert_construction_company_slide_pages[] = $expert_construction_company_mod;
            }
        }

        if (!empty($expert_construction_company_slide_pages)) :
            $expert_construction_company_args = array(
                'post_type' => 'page',
                'post__in' => $expert_construction_company_slide_pages,
                'orderby' => 'post__in'
            );
            $expert_construction_company_query = new WP_Query($expert_construction_company_args);
            if ($expert_construction_company_query->have_posts()) :
                while ($expert_construction_company_query->have_posts()) : $expert_construction_company_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 { ?>
                            <img src="<?php echo esc_url(get_template_directory_uri() . '/assets/images/slider.png'); ?>" alt="<?php echo esc_attr(get_the_title()); ?>" />
                        <?php } ?>
                        <div class="container">
                            <div class="carousel-caption">
                                <div class="inner_carousel wow fadeInRight" data-wow-delay="0.5s">
                                    <?php if (get_theme_mod('expert_construction_company_slider_short_heading') != '') { ?>
                                        <p class="slidetop-text mb-1"><?php echo esc_html(get_theme_mod('expert_construction_company_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="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__('LEARN MORE', 'expert-construction-company'); ?>
                                            </a>
                                        </span>
                                        <!-- Second button  -->
                                        <span class="slide-btn2">
                                            <?php
                                            $expert_construction_company_slider_btn_text = get_theme_mod('expert_construction_company_slider_btn_text', 'MAKE AN APPOINTMENT');
                                            $expert_construction_company_slider_btn_link = get_theme_mod('expert_construction_company_slider_btn_link');

                                            if (!empty($expert_construction_company_slider_btn_text) && !empty($expert_construction_company_slider_btn_link)) { ?>
                                                <a href="<?php echo esc_url($expert_construction_company_slider_btn_link); ?>" class="btn-text">
                                                    <?php echo esc_html($expert_construction_company_slider_btn_text); ?>
                                                </a>
                                            <?php } ?>
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endwhile;
                wp_reset_postdata(); ?>
            <?php else : ?>
                <div class="no-postfound"></div>
            <?php endif;
        endif; ?>
    </div>

    <?php if (get_theme_mod('expert_construction_company_slider_below_call_text') || get_theme_mod('expert_construction_company_slider_below_call')) : ?>
            <div class="container">
        <div class="slider-call mb-4 wow fadeIn">
                <div class="slider-call-icon">
                    <i class="far fa-calendar-alt me-2"></i>
                </div>
                <div class="slider-call-content">
                    <p class="slider-appointment-text text-capitalize"><?php echo esc_html(get_theme_mod('expert_construction_company_slider_below_call_text', '')); ?></p>
                    <p class="mb-0 slider-appointment">
                        <a href="tel:<?php echo esc_html(get_theme_mod('expert_construction_company_slider_below_call', '')); ?>">
                            <?php echo esc_html(get_theme_mod('expert_construction_company_slider_below_call', '')); ?>
                        </a>
                    </p>
                </div>
            </div>
        </div>
    <?php endif; ?>
</section>
<?php endif; ?>
