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

$fast_food_joint_slider_content_ids  = array();
$fast_food_joint_slider_content_type = get_theme_mod( 'fast_food_joint_banner_slider_content_type', 'post' );

for ( $i = 1; $i <= 3; $i++ ) {
	$fast_food_joint_slider_content_ids[] = get_theme_mod( 'fast_food_joint_banner_slider_content_' . $fast_food_joint_slider_content_type . '_' . $i );
}
$fast_food_joint_banner_slider_args = array(
	'post_type'           => $fast_food_joint_slider_content_type,
	'post__in'            => array_filter( $fast_food_joint_slider_content_ids ),
	'orderby'             => 'post__in',
	'posts_per_page'      => absint( 3 ),
	'ignore_sticky_posts' => true,
);
$fast_food_joint_banner_slider_args = apply_filters( 'fast_food_joint_banner_section_args', $fast_food_joint_banner_slider_args );

fast_food_joint_render_banner_section( $fast_food_joint_banner_slider_args );

/**
 * Render Banner Section.
 */
function fast_food_joint_render_banner_section( $fast_food_joint_banner_slider_args ) {     ?>

	<section id="fast_food_joint_banner_section" class="banner-section banner-style-1">
		<?php
		if ( is_customize_preview() ) :
			fast_food_joint_section_link( 'fast_food_joint_banner_section' );
		endif;
		?>
		<div class="banner-section-wrapper">
			<?php
			$fast_food_joint_query = new WP_Query( $fast_food_joint_banner_slider_args );
			if ( $fast_food_joint_query->have_posts() ) :
				?>
				<div class="asterthemes-banner-wrapper banner-slider fast-food-joint-carousel-navigation" data-slick='{"autoplay": false }'>
					<?php
					$i = 1;
					while ( $fast_food_joint_query->have_posts() ) :
						$fast_food_joint_query->the_post();
						$fast_food_joint_button_label = get_theme_mod( 'fast_food_joint_banner_button_label_' . $i, 'View Offer' );
						$fast_food_joint_button_link  = get_theme_mod( 'fast_food_joint_banner_button_link_' . $i, '' );
						$fast_food_joint_button_link  = ! empty( $fast_food_joint_button_link ) ? $fast_food_joint_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" alt="Default Image" />
									<?php endif; ?>
								</div>
								<div class="banner-caption">
									<div class="asterthemes-wrapper">
										<div class="banner-catption-wrapper wow fadeInDown" data-wow-duration="1.5s">
											<h1 class="banner-caption-title">
											    <?php
											    $fast_food_joint_title = get_the_title();
											    echo $fast_food_joint_title;
											    ?>
											</h1>
											<div class="mag-post-excerpt">
												<?php the_excerpt(); ?>
											</div>
											<?php if ( ! empty( $fast_food_joint_button_label ) ) { ?>
												<div class="banner-slider-btn">
													<a href="<?php echo esc_url( $fast_food_joint_button_link ); ?>" class="asterthemes-button"><?php echo esc_html( $fast_food_joint_button_label ); ?></a>
												</div>
											<?php } ?>
										</div>
									</div>
								</div>
							</div>
						</div>
						<?php
						$i++;
					endwhile;
					wp_reset_postdata();
					?>
				</div>
				<?php
			endif;
			?>
		</div>
	</section>
	<?php
}