<?php
if ( ! get_theme_mod( 'wheel_alignment_service_enable_banner_section', false ) ) {
	return;
}

$wheel_alignment_service_slider_content_ids  = array();
$wheel_alignment_service_slider_content_type = get_theme_mod( 'wheel_alignment_service_banner_slider_content_type', 'post' );

for ( $wheel_alignment_service_i = 1; $wheel_alignment_service_i <= 3; $wheel_alignment_service_i++ ) {
	$wheel_alignment_service_slider_content_ids[] = get_theme_mod( 'wheel_alignment_service_banner_slider_content_' . $wheel_alignment_service_slider_content_type . '_' . $wheel_alignment_service_i );
}

// Get the category for the banner slider from theme mods or a default category
$wheel_alignment_service_banner_slider_category = get_theme_mod('wheel_alignment_service_banner_slider_category', 'Slider');

// Modify query to fetch posts from a specific category
$wheel_alignment_service_banner_slider_args = array(
    'post_type'           => $wheel_alignment_service_slider_content_type,
    'post__in'            => array_filter( $wheel_alignment_service_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' === $wheel_alignment_service_slider_content_type && ! empty( $wheel_alignment_service_banner_slider_category ) ) {
    $wheel_alignment_service_banner_slider_args['category_name'] = $wheel_alignment_service_banner_slider_category;
}

$wheel_alignment_service_banner_slider_args = apply_filters( 'wheel_alignment_service_banner_section_args', $wheel_alignment_service_banner_slider_args );

wheel_alignment_service_render_banner_section( $wheel_alignment_service_banner_slider_args );

/**
 * Render Banner Section.
 */
function wheel_alignment_service_render_banner_section( $wheel_alignment_service_banner_slider_args ) {     ?>

	<section id="wheel_alignment_service_banner_section" class="banner-section banner-style-1">
		<?php
		if ( is_customize_preview() ) :
			wheel_alignment_service_section_link( 'wheel_alignment_service_banner_section' );
		endif;
		?>
		<div class="banner-section-wrapper">
			<?php
			$wheel_alignment_service_query = new WP_Query( $wheel_alignment_service_banner_slider_args );
			if ( $wheel_alignment_service_query->have_posts() ) :
				?>
				<div class="asterthemes-banner-wrapper banner-slider wheel-alignment-service-carousel-navigation" data-slick='{"autoplay": false }'>
					<?php
					$wheel_alignment_service_i = 1;
					while ( $wheel_alignment_service_query->have_posts() ) :
						$wheel_alignment_service_query->the_post();
						$wheel_alignment_service_button_label = get_theme_mod( 'wheel_alignment_service_banner_button_label_' . $wheel_alignment_service_i, '' );
						$wheel_alignment_service_button_link  = get_theme_mod( 'wheel_alignment_service_banner_button_link_' . $wheel_alignment_service_i, '' );
						$wheel_alignment_service_button_link  = ! empty( $wheel_alignment_service_button_link ) ? $wheel_alignment_service_button_link : get_the_permalink();
						?>
						<div class="banner-single-outer">
							<div class="banner-single">
								<div class="banner-img">
                                    <?php if ( has_post_thumbnail() ) : ?>
                                        <?php the_post_thumbnail( 'full' ); ?>
                                    <?php else : ?>
                                        <img src="<?php echo esc_url( get_template_directory_uri() ); ?>/resource/img/default.png" />
                                    <?php endif; ?>
									<div class="banner-overlay"></div>
                                </div>
								<h1 class="banner-side">
									<?php echo esc_html( get_theme_mod( 'wheel_alignment_service_banner_side_heading', 'WHEELALLIGNMENT' ) ); ?>
								</h1>
								<div class="banner-caption">
								    <div class="asterthemes-wrapper">
								        <div class="banner-catption-wrapper wow fadeInDown" data-wow-duration="1.5s">
								        	<!-- New Heading from Customizer -->
								            <h2 class="custom-banner-heading">
										    <?php echo esc_html( get_theme_mod( 'wheel_alignment_service_banner_heading') ); ?>
											</h2>

								            <a href="<?php the_permalink(); ?>"> <h1 class="banner-caption-title"><?php the_title(); ?></h1> </a>
								            <div class="mag-post-excerpt">
								                <?php the_excerpt(); ?>
								            </div>
								            <?php if ( ! empty( $wheel_alignment_service_button_label ) ) { ?>
								                <div class="banner-slider-btn">
								                    <a href="<?php echo esc_url( $wheel_alignment_service_button_link ); ?>" class="asterthemes-button"><?php echo esc_html( $wheel_alignment_service_button_label ); ?></a>
								                </div>
								            <?php } ?>
								            
								        </div>
								    </div>
								</div>
							</div>
						</div>
						<?php
						$wheel_alignment_service_i++;
					endwhile;
					wp_reset_postdata();
					?>
				</div>
				<?php
			endif;
			?>
		</div>
	</section>

	<?php
}