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

$moving_truck_rental_slider_content_ids  = array();
$moving_truck_rental_slider_content_type = get_theme_mod( 'moving_truck_rental_banner_slider_content_type', 'post' );

for ( $moving_truck_rental_i = 1; $moving_truck_rental_i <= 3; $moving_truck_rental_i++ ) {
	$moving_truck_rental_slider_content_ids[] = get_theme_mod( 'moving_truck_rental_banner_slider_content_' . $moving_truck_rental_slider_content_type . '_' . $moving_truck_rental_i );
}
$moving_truck_rental_banner_slider_args = array(
	'post_type'           => $moving_truck_rental_slider_content_type,
	'post__in'            => array_filter( $moving_truck_rental_slider_content_ids ),
	'orderby'             => 'post__in',
	'posts_per_page'      => absint( 3 ),
	'ignore_sticky_posts' => true,
);
$moving_truck_rental_banner_slider_args = apply_filters( 'moving_truck_rental_banner_section_args', $moving_truck_rental_banner_slider_args );

moving_truck_rental_render_banner_section( $moving_truck_rental_banner_slider_args );

/**
 * Render Banner Section.
 */
function moving_truck_rental_render_banner_section( $moving_truck_rental_banner_slider_args ) {     ?>

	<section id="moving_truck_rental_banner_section" class="banner-section banner-style-1">
		<?php
		if ( is_customize_preview() ) :
			moving_truck_rental_section_link( 'moving_truck_rental_banner_section' );
		endif;
		?>
		<div class="banner-section-wrapper">
			<?php
			$moving_truck_rental_query = new WP_Query( $moving_truck_rental_banner_slider_args );
			if ( $moving_truck_rental_query->have_posts() ) :
				?>
				<div class="asterthemes-banner-wrapper banner-slider moving-truck-rental-carousel-navigation" data-slick='{"autoplay": false }'>
					<?php
					$moving_truck_rental_i = 1;
					while ( $moving_truck_rental_query->have_posts() ) :
						$moving_truck_rental_query->the_post();
						$moving_truck_rental_button_label = get_theme_mod( 'moving_truck_rental_banner_button_label_' . $moving_truck_rental_i, '' );
						$moving_truck_rental_button_link  = get_theme_mod( 'moving_truck_rental_banner_button_link_' . $moving_truck_rental_i, '' );
						$moving_truck_rental_button_link  = ! empty( $moving_truck_rental_button_link ) ? $moving_truck_rental_button_link : get_the_permalink();
						$moving_truck_rental_button_label_1 = get_theme_mod( 'moving_truck_rental_banner_button_label_1' . $moving_truck_rental_i, '' );
						$moving_truck_rental_button_link_1  = get_theme_mod( 'moving_truck_rental_banner_button_link_1' . $moving_truck_rental_i, '' );
						?>
						<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.jpg" alt="Default Image" />
									<?php endif; ?>
								</div>
								<div class="banner-caption">
									<div class="asterthemes-wrapper">
										<div class="banner-catption-wrapper">
											<h1 class="banner-caption-title">
											    <?php
											    $title = get_the_title();
											    echo $title;
											    ?>
											</h1>
											<div class="mag-post-excerpt">
												<?php the_excerpt(); ?>
											</div>
											<?php if ( ! empty( $moving_truck_rental_button_label ) ) { ?>
												<div class="banner-slider-btn">
													<a href="<?php echo esc_url( $moving_truck_rental_button_link ); ?>" class="asterthemes-button"><?php echo esc_html( $moving_truck_rental_button_label ); ?></a>
												</div>
											<?php } ?>
											<?php if ( ! empty( $moving_truck_rental_button_label_1 ) ) { ?>
												<div class="banner-slider-btn slide-btn-2">
													<a href="<?php echo esc_url( $moving_truck_rental_button_link_1 ); ?>" class="asterthemes-button"><?php echo esc_html( $moving_truck_rental_button_label_1 ); ?></a>
												</div>
											<?php } ?>
										</div>

									</div>
								</div>
							</div>
						</div>
						<?php
						$moving_truck_rental_i++;
					endwhile;
					wp_reset_postdata();
					?>
				</div>
				<?php
			endif;
			?>
		</div>
	</section>
	<?php
}