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

$interior_services_services_category = get_theme_mod( 'interior_services_services_category', 'services' );

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

if ( ! empty( $interior_services_services_category ) ) {
	$interior_services_services_args['category_name'] = $interior_services_services_category;
}

$interior_services_services_args = apply_filters( 'interior_services_services_section_args', $interior_services_services_args );

interior_services_render_services_section( $interior_services_services_args );

function interior_services_render_services_section() {
	$interior_services_heading = get_theme_mod( 'interior_services_trending_post_heading' );
	$interior_services_subheading = get_theme_mod( 'interior_services_trending_post_content' );
	?>
	<section id="interior_services_services_section" class="asterthemes-frontpage-section services-section service-style-1 wow zoomInUp" data-wow-duration="1.5s">
		<?php if ( is_customize_preview() ) interior_services_section_link( 'interior_services_services_section' ); ?>

		<div class="asterthemes-wrapper service-contact-inner">
			<div class="services-inner">
				<?php if ( ! empty( $interior_services_subheading ) ) : ?>
					<p><?php echo esc_html( $interior_services_subheading ); ?></p>
				<?php endif; ?>
				<?php if ( ! empty( $interior_services_heading ) ) : ?>
					<h2><?php echo esc_html( $interior_services_heading ); ?></h2>
				<?php endif; ?>
			</div>
			<div class="video-main-box">
				<div class="section-body">
					<div class="service-section-wrapper">
						<?php
						$interior_services_featured_post = get_theme_mod('interior_services_services_post_count');
						for ($interior_services_i=1; $interior_services_i <= $interior_services_featured_post; $interior_services_i++) {
							$interior_services_services_name = get_theme_mod( 'interior_services_services_name' . $interior_services_i );
							$post_id = get_theme_mod( 'interior_services_services_content_post_' . $interior_services_i );
							if ( $post_id ) {
								$post = get_post( $post_id );
								setup_postdata( $post );
								?>
								<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="service-content">
										<p class="mb-0"><?php echo wp_trim_words( get_the_content(), 15 ); ?></p>
									</div>
									<p class="service-btn mt-3">
										<a href="<?php echo esc_url(get_permalink($post->ID)); ?>"><?php esc_html_e('Know More', 'interior-services'); ?>
										<i class="fas fa-arrow-right"></i>
										</a>
									</p>
                                    <div class="services-info">
										<div class="service-icon">
											<?php if(get_theme_mod('interior_services_services_icon'.$interior_services_i)){ ?>
												<i class="<?php echo esc_attr(get_theme_mod('interior_services_services_icon'.$interior_services_i)); ?>"></i>
											<?php } ?>
										</div>
										<div class="services-name">
											<?php if ( $interior_services_services_name ) : ?>
												<p><?php echo esc_html( $interior_services_services_name ); ?></p>									
											<?php endif; ?>
										</div>
									</div>
								</div>
								<?php
								wp_reset_postdata();
							}
						}
						?>
					</div>
				</div>
			</div>
		</div>
	</section>
	<?php
}
?>