<?php
/**
 * Template part for displaying slider section
 *
 * @package Estate Brokerage Services
 * @subpackage estate_brokerage_services
 */

$estate_brokerage_services_static_image = get_stylesheet_directory_uri() . '/assets/images/sliderimage.png';

if (get_theme_mod('estate_brokerage_services_slider_arrows', true) != '') : ?>

<section id="slider">
    <div class="container-fluid p-0">
        <?php
        $estate_brokerage_services_slide_pages = array();
        for ($estate_brokerage_services_count = 1; $estate_brokerage_services_count <= 1; $estate_brokerage_services_count++) {
            $estate_brokerage_services_mod = intval(get_theme_mod('estate_brokerage_services_slider_page' . $estate_brokerage_services_count, 0));
            if ($estate_brokerage_services_mod > 0) {
                $estate_brokerage_services_slide_pages[] = $estate_brokerage_services_mod;
            }
        }
        if (!empty($estate_brokerage_services_slide_pages)) :
            $estate_brokerage_services_args = array(
                'post_type' => 'page',
                'post__in' => $estate_brokerage_services_slide_pages,
                'orderby' => 'post__in'
            );
            $estate_brokerage_services_query = new WP_Query($estate_brokerage_services_args);
            if ($estate_brokerage_services_query->have_posts()) :
                while ($estate_brokerage_services_query->have_posts()) : $estate_brokerage_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 the_title_attribute(); ?>" />
                        <?php } else { ?>
                            <img src="<?php echo esc_url($estate_brokerage_services_static_image); ?>" alt="<?php esc_attr_e('Default Image', 'estate-brokerage-services'); ?>" />
                        <?php } ?>
                        <div class="carousel-caption">
                            <div class="position-relative">
                                <?php
                                $estate_brokerage_services_search_form = absint( get_theme_mod( 'estate_brokerage_services_search_form', 1 ) );
                                $estate_brokerage_services_search_status = get_theme_mod( 'estate_brokerage_services_search_status', 'rent' ); // New setting

                                if ( $estate_brokerage_services_search_form && shortcode_exists( 'ere_property_advanced_search' ) ) : ?>
                                 <!-- TOP LEFT STATUS TAB -->
                                <div class="search-status-tab">
                                    <span class="status-label status-<?php echo esc_attr($estate_brokerage_services_search_status); ?>">
                                        <?php echo esc_html( ucfirst($estate_brokerage_services_search_status) ); ?>
                                    </span>
                                </div>
                                <div class="slider-over-search mb-4 position-relative" aria-labelledby="searchform-heading">
                                    <?php
                                    /**
                                    * Property search box
                                    */
                                    echo do_shortcode('[ere_property_advanced_search 
                                        status_enable="false" 
                                        type_enable="true" 
                                        title_enable="false" 
                                        address_enable="true" 
                                        city_enable="false" 
                                        bedrooms_enable="true" 
                                        price_enable="true" 
                                        price_is_slider="false" 
                                        label_enable="false" 
                                        layout="horizontal" 
                                        column="6" 
                                        color_scheme="color-dark" 
                                        el_class="search-with-status"
                                    ]');
                                    ?>
                                </div>
                            <?php endif; ?>
                            </div>
                            <div class="inner_carousel">
                                <div class="title-slider-content">
                                    <?php if (get_theme_mod('estate_brokerage_services_show_slider_title', true)) : ?>
                                        <h1 class="custom-title my-0"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
                                    <?php endif; ?>
                                    <hr>
                                    <?php if (get_theme_mod('estate_brokerage_services_show_slider_content', true)) : ?>
                                        <p class="my-0 slider-content"><?php $estate_brokerage_services_excerpt = get_the_excerpt(); echo esc_html( estate_brokerage_services_string_limit_words( $estate_brokerage_services_excerpt, esc_attr(get_theme_mod('estate_brokerage_services_slider_excerpt_length','15')))); ?></p>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endwhile;
                wp_reset_postdata();
            else : ?>
                <div class="no-postfound"><?php esc_html_e('No slides found.', 'estate-brokerage-services'); ?></div>
            <?php endif;
        endif; ?>
    </div>
</section>
<?php endif; ?>