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

$appointment_management_slider_content_ids  = array();
$appointment_management_slider_content_type = get_theme_mod( 'appointment_management_banner_slider_content_type', 'post' );

for ( $appointment_management_i = 1; $appointment_management_i <= 3; $appointment_management_i++ ) {
	$appointment_management_slider_content_ids[] = get_theme_mod( 'appointment_management_banner_slider_content_' . $appointment_management_slider_content_type . '_' . $appointment_management_i );
}
// Get the category for the banner slider from theme mods or a default category
$appointment_management_banner_slider_category = get_theme_mod('appointment_management_banner_slider_category', 'slider');

// Modify query to fetch posts from a specific category
$appointment_management_banner_slider_args = array(
	'post_type'           => $appointment_management_slider_content_type,
	'post__in'            => array_filter( $appointment_management_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' === $appointment_management_slider_content_type && ! empty( $appointment_management_banner_slider_category ) ) {
	$appointment_management_banner_slider_args['category_name'] = $appointment_management_banner_slider_category;
}
$appointment_management_banner_slider_args = apply_filters( 'appointment_management_banner_section_args', $appointment_management_banner_slider_args );

appointment_management_render_banner_section( $appointment_management_banner_slider_args );

/**
 * Render Banner Section.
 */

function appointment_management_render_banner_section( $appointment_management_banner_slider_args ) {     ?>

	<section id="appointment_management_banner_section" class="banner-section banner-style-1">
		<?php
		if ( is_customize_preview() ) :
			appointment_management_section_link( 'appointment_management_banner_section' );
		endif;
		?>
		<div class="banner-section-wrapper">
			<?php
			$appointment_management_query = new WP_Query( $appointment_management_banner_slider_args );
			if ( $appointment_management_query->have_posts() ) :
				?>
				<div class="asterthemes-banner-wrapper banner-slider appointment-management-carousel-navigation" data-slick='{"autoplay": false }'>
					<?php
					$appointment_management_i = 1;
					while ( $appointment_management_query->have_posts() ) :
						$appointment_management_query->the_post();
						$appointment_management_button_label = get_theme_mod( 'appointment_management_banner_button_label_' . $appointment_management_i);
						$appointment_management_button_link  = get_theme_mod( 'appointment_management_banner_button_link_' . $appointment_management_i);
						$appointment_management_button_link  = ! empty( $appointment_management_button_link ) ? $appointment_management_button_link : esc_url(get_the_permalink());
						$appointment_management_about_left_image = get_theme_mod( 'appointment_management_about_left_image');
						$appointment_management_team_heading = get_theme_mod( 'appointment_management_team_heading');
						?>
						<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>
								<div class="banner-caption">
									<div class="asterthemes-wrapper">
										<div class="banner-catption-wrapper wow fadeInUp" data-wow-duration="1.5s">
											<a href="<?php the_permalink(); ?>"> <h2 class="banner-caption-title"><?php the_title(); ?></h2> </a>
											<div class="mag-post-excerpt">
												<?php the_excerpt(); ?>
											</div>
											<?php if ( ! empty( $appointment_management_button_label ) ) { ?>
												<div class="banner-slider-btn">
													<a href="<?php echo esc_url( $appointment_management_button_link ); ?>" class="asterthemes-button"><?php echo esc_html( $appointment_management_button_label ); ?></a>
												</div>
											<?php } ?>
										</div>
									</div>
								</div>
							</div>
						</div>
						<?php
						$appointment_management_i++;
					endwhile;
					wp_reset_postdata();
					?>
				</div>
				<?php
			endif;
			?>
		</div>
		<div class="contact-section">
			<?php
				$appointment_management_phone_text = get_theme_mod( 'appointment_management_phone_text');
				$appointment_management_phone_number = get_theme_mod( 'appointment_management_phone_number');
				$appointment_management_email_text = get_theme_mod( 'appointment_management_email_text');
				$appointment_management_email_address = get_theme_mod( 'appointment_management_email_address');
				$appointment_management_timing_text = get_theme_mod( 'appointment_management_timing_text');
				$appointment_management_opening_timing = get_theme_mod( 'appointment_management_opening_timing');
			?>
			<?php if ( ! empty( $appointment_management_phone_text ) || ! empty( $appointment_management_email_text ) || ! empty( $appointment_management_timing_text ) || ! empty( $appointment_management_phone_number ) || ! empty( $appointment_management_email_address ) || ! empty( $appointment_management_opening_timing ) ) { ?>
				<div class="contact-inner">
					<div class="contact-info">
						<div>
							<i class="<?php echo esc_attr(get_theme_mod('appointment_management_phone_icon','fas fa-phone-alt')); ?>"></i>
						</div>
						<div>
							<?php if ( ! empty( $appointment_management_phone_text ) ) { ?>
								<div class="banner-contact-inner">
								<h5 data-text="heading"><?php echo esc_html( $appointment_management_phone_text ); ?></h5>
								</div>
							<?php } ?>
							<?php if ( ! empty( $appointment_management_phone_number ) ) { ?>
								<a href="tel:<?php echo esc_attr(  substr( $appointment_management_phone_number, 0, 21 )  ); ?>"><span><?php echo esc_html(  substr( $appointment_management_phone_number, 0, 21 )  ); ?></span></a>
							<?php } ?>
						</div>
					</div>
					<div class="contact-info">
						<div>
							<i class="<?php echo esc_attr(get_theme_mod('appointment_management_address_icon','far fa-envelope')); ?>"></i>
						</div>
						<div>
							<?php if ( ! empty( $appointment_management_email_text ) ) { ?>
								<div class="banner-contact-inner">
								<h5 data-text="heading"><?php echo esc_html( $appointment_management_email_text ); ?></h5>
								</div>
							<?php } ?>
							<?php if ( ! empty( $appointment_management_email_address ) ) { ?>
								<a href="mailto:<?php echo esc_attr( $appointment_management_email_address ); ?>"><span><?php echo esc_html( $appointment_management_email_address ); ?></span></a>
							<?php } ?>
						</div>
					</div>
					<div class="contact-info">
						<div>
							<i class="<?php echo esc_attr(get_theme_mod('appointment_management_timing_icon', 'far fa-clock')); ?>"></i>
						</div>
						<div>
							<?php if ( ! empty( $appointment_management_timing_text ) ) { ?>
								<div class="banner-contact-inner">
								<h5 data-text="heading"><?php echo esc_html( $appointment_management_timing_text ); ?></h5>
								</div>
							<?php } ?>
							<?php if ( ! empty( $appointment_management_opening_timing ) ) { ?>
								<span><?php echo esc_html( $appointment_management_opening_timing ); ?></span>
							<?php } ?>
						</div>

					</div>
				</div>
			<?php } ?>
		</div>
	</section>

	<?php
}
