<?php
/**
 * Template Name: Home Page
 */

get_header();
?>

<main id="primary">

    <?php 
    $estate_rental_listings_main_slider_wrap = absint(get_theme_mod('estate_rental_listings_enable_slider', 0));
    if($estate_rental_listings_main_slider_wrap == 1): 
    ?>
    <section id="main-slider-wrap">
        <div class="owl-carousel">
            <?php for ($estate_rental_listings_main_i=1; $estate_rental_listings_main_i <= 3; $estate_rental_listings_main_i++): ?>
                <?php if ($estate_rental_listings_slider_image = get_theme_mod('estate_rental_listings_slider_image'.$estate_rental_listings_main_i)): ?>
                    <div class="main-slider-inner-box">
                        <img src="<?php echo esc_url($estate_rental_listings_slider_image); ?>" alt="<?php echo esc_attr( get_theme_mod('estate_rental_listings_slider_heading'.$estate_rental_listings_main_i) ); ?>">
                        <div class="main-slider-content-box">
                            <?php if ($estate_rental_listings_top_text = get_theme_mod('estate_rental_listings_slider_top_text'.$estate_rental_listings_main_i)): ?>
                                <p class="slider-top"><?php echo esc_html($estate_rental_listings_top_text); ?></p>
                            <?php endif; ?>
                            <?php if ($estate_rental_listings_heading = get_theme_mod('estate_rental_listings_slider_heading'.$estate_rental_listings_main_i)): ?>
                                <h1><?php echo esc_html($estate_rental_listings_heading); ?></h1>
                            <?php endif; ?>
                            <?php if ($estate_rental_listings_text = get_theme_mod('estate_rental_listings_slider_text'.$estate_rental_listings_main_i)): ?>
                                <p><?php echo esc_html($estate_rental_listings_text); ?></p>
                            <?php endif; ?>
                            <div class="main-slider-button">
                                <?php if ($estate_rental_listings_button_link = get_theme_mod('estate_rental_listings_slider_button1_link'.$estate_rental_listings_main_i) && $estate_rental_listings_button_text = get_theme_mod('estate_rental_listings_slider_button1_text'.$estate_rental_listings_main_i)): ?>
                                    <a href="<?php echo esc_url($estate_rental_listings_button_link); ?>"><?php echo esc_html($estate_rental_listings_button_text); ?><i class="fas fa-angle-double-right"></i></a>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                <?php endif; ?>
            <?php endfor; ?>
        </div>
    </section>
    <?php endif; ?>

    <?php 
    $estate_rental_listings_main_expert_wrap = absint(get_theme_mod('estate_rental_listings_enable_event', 0));
    if($estate_rental_listings_main_expert_wrap == 1): 
        $estate_rental_listings_catData2 = get_theme_mod('estate_rental_listings_blog_cat','uncategorized');

        if(!empty($estate_rental_listings_catData2) && $estate_rental_listings_catData2 !== 'select'): 
            $estate_rental_listings_page_query = new WP_Query(array( 
                'category_name' => esc_html($estate_rental_listings_catData2),
                'posts_per_page' => -1  // Fetch all posts from the category
            ));

            if($estate_rental_listings_page_query->have_posts()): ?>
                <section id="main-expert-wrap">
                    <div class="container">
                        <div class="heading-expert-wrap">
                            <?php if ($estate_rental_listings_event_heading = get_theme_mod('estate_rental_listings_event_heading')): ?>
                                <p><?php echo esc_html($estate_rental_listings_event_heading); ?></p>
                            <?php endif; ?>
                            <?php if ($estate_rental_listings_event_text = get_theme_mod('estate_rental_listings_event_text')): ?>
                                <h2><?php echo esc_html($estate_rental_listings_event_text); ?></h2>
                            <?php endif; ?>
                        </div>
                        <div id="primary">
                            <div class="owl-carousel">
                                <?php while($estate_rental_listings_page_query->have_posts()): $estate_rental_listings_page_query->the_post(); ?>
                                    <div class="box">
                                        <div class="box-image">
                                            <?php if(has_post_thumbnail()) { the_post_thumbnail(); } ?>
                                        </div>
                                        <div class="box-content">
                                            <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
                                        </div>
                                        <div class="clearfix"></div> 
                                    </div>          
                                <?php endwhile; wp_reset_postdata(); ?>
                            </div>
                        </div>                
                    </div>
                </section>
            <?php else: ?>
                <p><?php esc_html_e('No posts found in this category.', 'estate-rental-listings'); ?></p>
            <?php endif; 
        endif; 
    endif; 
    ?>

</main>

<?php
get_footer();
?>