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

$doctor_physician_slider_content_ids  = array();
$doctor_physician_slider_content_type = get_theme_mod( 'doctor_physician_banner_slider_content_type', 'post' );

for ( $doctor_physician_i = 1; $doctor_physician_i <= 3; $doctor_physician_i++ ) {
	$doctor_physician_slider_content_ids[] = get_theme_mod( 'doctor_physician_banner_slider_content_' . $doctor_physician_slider_content_type . '_' . $doctor_physician_i );
}
// Get the category for the banner slider from theme mods or a default category
$doctor_physician_banner_slider_category = get_theme_mod('doctor_physician_banner_slider_category', 'slider');

// Modify query to fetch posts from a specific category
$doctor_physician_banner_slider_args = array(
	'post_type'           => $doctor_physician_slider_content_type,
	'post__in'            => array_filter( $doctor_physician_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' === $doctor_physician_slider_content_type && ! empty( $doctor_physician_banner_slider_category ) ) {
	$doctor_physician_banner_slider_args['category_name'] = $doctor_physician_banner_slider_category;
}
$doctor_physician_banner_slider_args = apply_filters( 'doctor_physician_banner_section_args', $doctor_physician_banner_slider_args );

doctor_physician_render_banner_section( $doctor_physician_banner_slider_args );

/**
 * Render Banner Section.
 */
function doctor_physician_render_banner_section( $doctor_physician_banner_slider_args ) {     ?>

	<section id="doctor_physician_banner_section" class="banner-section banner-style-1">
		<?php
		if ( is_customize_preview() ) :
			doctor_physician_section_link( 'doctor_physician_banner_section' );
		endif;
		?>
		<div class="banner-section-wrapper">
			<?php
			$doctor_physician_query = new WP_Query( $doctor_physician_banner_slider_args );
			if ( $doctor_physician_query->have_posts() ) :
				?>
				<div class="asterthemes-banner-wrapper banner-slider doctor-physician-carousel-navigation" data-slick='{"autoplay": false }'>
					<?php
					$doctor_physician_i = 1;
					while ( $doctor_physician_query->have_posts() ) :
						$doctor_physician_query->the_post();
						$doctor_physician_button_label = get_theme_mod( 'doctor_physician_banner_button_label_' . $doctor_physician_i);
						$doctor_physician_button_link  = get_theme_mod( 'doctor_physician_banner_button_link_' . $doctor_physician_i);
						$doctor_physician_button_link  = ! empty( $doctor_physician_button_link ) ? $doctor_physician_button_link : esc_url(get_the_permalink());
						$doctor_physician_about_left_image = get_theme_mod( 'doctor_physician_about_left_image');
						$doctor_physician_team_heading = get_theme_mod( 'doctor_physician_team_heading');
						?>
						<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">
											<h2 class="banner-caption-title">
												<?php the_title(); ?>
											</h2>
											<div class="mag-post-excerpt">
												<?php the_excerpt(); ?>
											</div>
											<?php if ( ! empty( $doctor_physician_button_label ) ) { ?>
												<div class="banner-slider-btn">
													<a href="<?php echo esc_url( $doctor_physician_button_link ); ?>" class="asterthemes-button"><?php echo esc_html( $doctor_physician_button_label ); ?></a>
												</div>
											<?php } ?>
										</div>
									</div>
								</div>
								<div class="team-box">
									<?php if ( ! empty( $doctor_physician_about_left_image ) ) { ?>
										<div class="teams-image">
											<img src="<?php echo esc_url( $doctor_physician_about_left_image ); ?>" alt="<?php the_title_attribute(); ?>">
										</div>
									<?php } ?>
									<div class="team-content">
										<?php if ( ! empty( $doctor_physician_team_heading ) ) { ?>
											  <p class="team"><?php echo esc_html( $doctor_physician_team_heading ); ?></p>
										<?php } ?>
									</div>
								</div>
							</div>
						</div>
						<?php
						$doctor_physician_i++;
					endwhile;
					wp_reset_postdata();
					?>
				</div>
				<?php
			endif;
			?>
		</div>
	</section>

	<?php
}
