<?php
/**
 * Banner Sections
 *
 * Displays latest posts in banner section with Swiper slider
 *
 */

// Query for latest posts for the slider
$hero_args = array(
	'post_type'           => 'post',
	'posts_per_page'      => 5, // Changed from 1 to 5 for multiple slides
	'post_status'         => 'publish',
	'orderby'             => 'date',
	'order'               => 'DESC',
	'ignore_sticky_posts' => true,
	// Optional: Only show posts with featured images
	'meta_query'          => array(
		array(
			'key'     => '_thumbnail_id',
			'compare' => 'EXISTS'
		),
	),
);

$hero_query = new WP_Query( $hero_args );

if ( $hero_query->have_posts() ) : ?>

    <!-- Hero Slider -->
    <div class="banner-section-wrapper">
        <div class="swiper bannerSwiper">
            <div class="swiper-wrapper">
				<?php while ( $hero_query->have_posts() ) : $hero_query->the_post();
					// Get featured image URL
					$featured_img = get_the_post_thumbnail_url( get_the_ID(), 'full' );

					// Fallback image if no featured image
					if ( ! $featured_img ) {
						$featured_img = get_template_directory_uri() . '/assets/images/banner.jpg';
					}

					// Get excerpt
					$excerpt = has_excerpt() ? get_the_excerpt() : wp_trim_words( get_the_content(), 30 );
					?>
                    <div class="swiper-slide">
                        <div class="banner-container-bg" style="background-image: url('<?php echo esc_url( $featured_img ); ?>');">
                            <div class="container-fluid">
                                <div class="row align-items-center">
                                    <div class="col">
                                        <div class="banner-content">
                                            <h1 class="banner-title">
                                                <a href="<?php the_permalink(); ?>">
													<?php the_title(); ?>
                                                </a>
                                            </h1>

                                            <p class="banner-short-description">
												<?php echo esc_html( $excerpt ); ?>
                                            </p>

                                            <a href="<?php the_permalink(); ?>" class="btn-read-more">
                                                READ MORE
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
				<?php endwhile; ?>
            </div>

            <!-- Navigation buttons -->
            <div class="swiper-button-next"></div>
            <div class="swiper-button-prev"></div>

            <!-- Pagination -->
            <div class="swiper-pagination"></div>
        </div>
    </div>

	<?php
	wp_reset_postdata();
endif;
?>