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

$slider_content_ids  = array();
$slider_content_type = get_theme_mod( 'fuzion_blog_slider_content_type', 'post' );

for ( $i = 1; $i <= 5; $i++ ) {
	$slider_content_ids[] = get_theme_mod( 'fuzion_blog_slider_content_' . $slider_content_type . '_' . $i );
}
$slider_args = array(
	'post_type'           => $slider_content_type,
	'posts_per_page'      => absint( 5 ),
	'ignore_sticky_posts' => true,
);

if ( ! empty( array_filter( $slider_content_ids ) ) ) {
	$slider_args['post__in'] = array_filter( $slider_content_ids );
	$slider_args['orderby']  = 'post__in';
} else {
	$slider_args['orderby'] = 'date';
}

$slider_args = apply_filters( 'fuzion_blog_slider_section_args', $slider_args );

fuzion_blog_render_slider_section( $slider_args );

/**
 * Render Banner Slider Section.
 */
function fuzion_blog_render_slider_section( $slider_args ) {

	$query = new WP_Query( $slider_args );
	if ( $query->have_posts() ) {
		?>
		<section id="fuzion_blog_slider_section" class="banner-section banner-style-2">
			<?php
			if ( is_customize_preview() ) :
				fuzion_blog_section_link( 'fuzion_blog_slider_section' );
			endif;
			?>
			<div class="banner-wrapper">
				<div class="banner-slider slick-button">
					<?php
					while ( $query->have_posts() ) :
						$query->the_post();
						?>
						<div class="blog-post-container tile-layout">
							<div class="blog-post-inner">
								<div class="blog-post-image">
									<a href="<?php the_permalink(); ?>">
										<?php the_post_thumbnail( 'post-thumbnail' ); ?>
									</a>
									<div class="post-meta-comment">
										<span class="post-comments">
											<a href="<?php the_permalink(); ?>"><i class="fa fa-comment" aria-hidden="true"></i><?php echo absint( get_comments_number( get_the_ID() ) ); ?></a>
										</span>
									</div>
								</div>
								<div class="blog-post-detail">
									<div class="post-category">
										<?php the_category( '', '', get_the_ID() ); ?>
									</div>
									<h3 class="post-main-title">
										<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
									</h3>
									<div class="post-meta">
										<span class="post-author">
											<a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>"><i class="fa-regular fa-circle-user"></i><?php echo esc_html( get_the_author() ); ?></a>
										</span>
										<span class="post-date">
											<a href="<?php the_permalink(); ?>"><i class="fa-regular fa-calendar"></i><?php echo esc_html( get_the_date() ); ?></a>
										</span>
									</div>
								</div>
							</div>
						</div>
						<?php
					endwhile;
					wp_reset_postdata();
					?>
				</div>
			</div>
		</section>
		<?php
	}
}
