<?php
if ( ! get_theme_mod( 'resort_motel_enable_banner_section', true ) ) {
	return;
}

$resort_motel_slider_content_ids  = array();
$resort_motel_slider_content_type = get_theme_mod( 'resort_motel_banner_slider_content_type', 'post' );

for ( $resort_motel_i = 1; $resort_motel_i <= 3; $resort_motel_i++ ) {
	$resort_motel_slider_content_ids[] = get_theme_mod( 'resort_motel_banner_slider_content_' . $resort_motel_slider_content_type . '_' . $resort_motel_i );
}
// Get the category for the banner slider from theme mods or a default category
$resort_motel_banner_slider_category = get_theme_mod('resort_motel_banner_slider_category', 'slider');

// Modify query to fetch posts from a specific category
$resort_motel_banner_slider_args = array(
    'post_type'           => $resort_motel_slider_content_type,
    'post__in'            => array_filter( $resort_motel_slider_content_ids ),
    'orderby'             => 'post__in',
    'posts_per_page'      => absint(3),
    'ignore_sticky_posts' => true,
);

// Apply category filter only if content type is 'post'
if ( 'post' === $resort_motel_slider_content_type && ! empty( $resort_motel_banner_slider_category ) ) {
    $resort_motel_banner_slider_args['category_name'] = $resort_motel_banner_slider_category;
}

$resort_motel_banner_slider_args = apply_filters( 'resort_motel_banner_section_args', $resort_motel_banner_slider_args );

resort_motel_render_banner_section( $resort_motel_banner_slider_args );

/**
 * Render Banner Section.
 */
function resort_motel_render_banner_section( $resort_motel_banner_slider_args ) { ?>

    <section id="resort_motel_banner_section" class="banner-section banner-style-1">
        <?php
        if ( is_customize_preview() ) :
            resort_motel_section_link( 'resort_motel_banner_section' );
        endif;
        ?>
        <div class="banner-section-wrapper">
            <?php
            $resort_motel_query = new WP_Query( $resort_motel_banner_slider_args );
            if ( $resort_motel_query->have_posts() ) :
                ?>
                <div class="asterthemes-banner-wrapper banner-slider resort-motel-carousel-navigation" data-slick='{"autoplay": false }'>
                    <?php
                    $resort_motel_i = 1;
                    while ( $resort_motel_query->have_posts() ) :
                        $resort_motel_query->the_post();
                        $resort_motel_button_label = get_theme_mod( 'resort_motel_banner_button_label_' . $resort_motel_i);
                        $resort_motel_button_link  = get_theme_mod( 'resort_motel_banner_button_link_' . $resort_motel_i);
                        $resort_motel_button_link  = ! empty( $resort_motel_button_link ) ? $resort_motel_button_link : get_the_permalink();
                        $resort_motel_subtitle = get_theme_mod( 'resort_motel_banner_subtitle');
                        ?>
                        <div class="banner-single-outer">
                            <div class="banner-single">
                                <div class="banner-img">
                                    <?php the_post_thumbnail( 'full' ); ?>
                                </div>
                                <div class="banner-caption">
                                    <div class="asterthemes-wrapper">
                                        <div class="banner-catption-wrapper">
                                            <?php if ( ! empty( $resort_motel_subtitle ) ) { ?>
                                                <div class="banner-subtitle">
                                                    <p><?php echo esc_html( $resort_motel_subtitle ); ?></p>
                                                </div>
                                            <?php } ?>
                                            <h1 class="banner-caption-title wow fadeInDown" data-wow-duration="1.5s">
                                                <?php the_title(); ?>
                                            </h1>
                                            <?php if ( ! empty( $resort_motel_button_label ) ) { ?>
                                                <div class="banner-slider-btn">
                                                    <a href="<?php echo esc_url( $resort_motel_button_link ); ?>" class="asterthemes-button"><?php echo esc_html( $resort_motel_button_label ); ?></a>
                                                </div>
                                            <?php } ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php
                        $resort_motel_i++;
                    endwhile;
                    wp_reset_postdata();
                    ?>
                </div>
                <?php
            endif;
            ?>
        </div>
    </section>

    <?php
}