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

$aster_it_courses_courses_category = get_theme_mod( 'aster_it_courses_courses_category', 'courses' );

// Query posts from selected category
$aster_it_courses_courses_args = array(
	'post_type'           => 'post',
	'posts_per_page' 	  => -1,
	'ignore_sticky_posts' => true,
);

if ( ! empty( $aster_it_courses_courses_category ) ) {
	$aster_it_courses_courses_args['category_name'] = $aster_it_courses_courses_category;
}

$aster_it_courses_courses_args = apply_filters( 'aster_it_courses_service_section_args', $aster_it_courses_courses_args );

aster_it_courses_render_service_section( $aster_it_courses_courses_args );

function aster_it_courses_render_service_section() {
	$aster_it_courses_heading = get_theme_mod( 'aster_it_courses_trending_post_heading' );
	$aster_it_courses_subheading = get_theme_mod( 'aster_it_courses_trending_post_content' );
	?>
	<section id="aster_it_courses_service_section" class="asterthemes-frontpage-section service-section service-style-1 wow zoomInUp" data-wow-duration="1.5s">
		<?php if ( is_customize_preview() ) aster_it_courses_section_link( 'aster_it_courses_service_section' ); ?>

		<div class="asterthemes-wrapper service-contact-inner">
			<div class="courses-inner">
				<?php if ( ! empty( $aster_it_courses_subheading ) ) : ?>
					<p><?php echo esc_html( $aster_it_courses_subheading ); ?></p>
				<?php endif; ?>
				<?php if ( ! empty( $aster_it_courses_heading ) ) : ?>
					<h2><?php echo esc_html( $aster_it_courses_heading ); ?></h2>
				<?php endif; ?>
			</div>

			<div class="video-main-box">
				<div class="section-body">
					<div class="service-section-wrapper">
						<?php
						$aster_it_courses_featured_post = get_theme_mod('aster_it_courses_service_post_count');
						for ($aster_it_courses_i=1; $aster_it_courses_i <= $aster_it_courses_featured_post; $aster_it_courses_i++) {
							$post_id = get_theme_mod( 'aster_it_courses_service_content_post_' . $aster_it_courses_i );
							if ( $post_id ) {
								$post = get_post( $post_id );
								setup_postdata( $post );

								$aster_it_courses_author_image = get_theme_mod( 'aster_it_courses_author_image' . $aster_it_courses_i );
								$aster_it_courses_author_name = get_theme_mod( 'aster_it_courses_author_name' . $aster_it_courses_i );
								?>
								<div class="service-single">
									<div class="service-image">
										<?php if ( has_post_thumbnail( $post_id ) ) {
											echo get_the_post_thumbnail( $post_id, 'full' );
										} else { ?>
											<img src="<?php echo esc_url( get_template_directory_uri() . '/resource/img/default.png' ); ?>" alt="<?php the_title_attribute(); ?>" />
										<?php } ?>
									</div>

									<div class="author-wrapper">
										<?php if ( $aster_it_courses_author_image ) : ?>
											<div class="author-image">
												<img src="<?php echo esc_url( $aster_it_courses_author_image ); ?>" alt="<?php esc_attr_e('author-image', 'aster-it-courses'); ?>">
											</div>
										<?php endif; ?>

										<?php if ( $aster_it_courses_author_name ) : ?>
											<div class="author-name">
												<p><?php echo esc_html( $aster_it_courses_author_name ); ?></p>
											</div>
										<?php endif; ?>
									</div>

									<div class="service-title">
										<h3><a href="<?php echo esc_url( get_permalink( $post_id ) ); ?>"><?php echo esc_html( get_the_title( $post_id ) ); ?></a></h3>
									</div>
									<div class="post-num">
										<div class="post-numbers">
											<div class="paper-num">
												<?php if( get_theme_mod('aster_it_courses_paper_count'.$aster_it_courses_i) != ''){ ?>
													<span class=""><i class="far fa-sticky-note"></i><?php echo esc_html(get_theme_mod('aster_it_courses_paper_count'.$aster_it_courses_i));?></span>
												<?php }?>
											</div>
											<div class="degree-num">
												<?php if( get_theme_mod('aster_it_courses_degree_count'.$aster_it_courses_i) != ''){ ?>
													<span class=""><i class="fas fa-user-graduate"></i><?php echo esc_html(get_theme_mod('aster_it_courses_degree_count'.$aster_it_courses_i));?></span>
												<?php }?>
											</div>
										</div>
										<div>
											<div class="post-price">
												<?php if( get_theme_mod('aster_it_courses_regular_price'.$aster_it_courses_i) != ''){ ?>
													<span class="price"><?php echo esc_html(get_theme_mod('aster_it_courses_regular_price'.$aster_it_courses_i));?></span>
												<?php }?>
											</div>
										</div>
									</div>
								</div>
								<?php
								wp_reset_postdata();
							}
						}
						?>
					</div>
				</div>
			</div>
		</div>
	</section>
	<?php
}
?>
