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

$main_banner_content_ids = $editor_content_ids = array();
$banner_content_type     = get_theme_mod( 'news_revolution_main_banner_content_type', 'post' );
$editor_content_type     = get_theme_mod( 'news_revolution_editor_choice_content_type', 'post' );

if ( $banner_content_type === 'post' ) {
	for ( $i = 1; $i <= 3; $i++ ) {
		$main_banner_content_ids[] = get_theme_mod( 'news_revolution_main_banner_content_post_' . $i );
	}
	$main_banner_args = array(
		'post_type'           => 'post',
		'post__in'            => array_filter( $main_banner_content_ids ),
		'orderby'             => 'post__in',
		'posts_per_page'      => absint( 3 ),
		'ignore_sticky_posts' => true,
	);
	if ( ! empty( array_filter( $main_banner_content_ids ) ) ) {
		$main_banner_args['post__in'] = array_filter( $main_banner_content_ids );
		$main_banner_args['orderby']  = 'post__in';
	} else {
		$main_banner_args['orderby'] = 'date';
	}
} else {
	$cat_content_id   = get_theme_mod( 'news_revolution_main_banner_content_category' );
	$main_banner_args = array(
		'cat'            => $cat_content_id,
		'posts_per_page' => absint( 3 ),
	);
}
$main_banner_args = apply_filters( 'news_revolution_banner_section_args', $main_banner_args );

if ( $editor_content_type === 'post' ) {
	for ( $i = 1; $i <= 5; $i++ ) {
		$editor_content_ids[] = get_theme_mod( 'news_revolution_editor_choice_content_post_' . $i );
	}
	$editor_args = array(
		'post_type'           => 'post',
		'post__in'            => array_filter( $editor_content_ids ),
		'orderby'             => 'post__in',
		'posts_per_page'      => absint( 5 ),
		'ignore_sticky_posts' => true,
	);
	if ( ! empty( array_filter( $editor_content_ids ) ) ) {
		$editor_args['post__in'] = array_filter( $editor_content_ids );
		$editor_args['orderby']  = 'post__in';
	} else {
		$editor_args['orderby'] = 'date';
	}
} else {
	$cat_content_id = get_theme_mod( 'news_revolution_editor_choice_content_category' );
	$editor_args    = array(
		'cat'            => $cat_content_id,
		'posts_per_page' => absint( 5 ),
	);
}

$editor_args = apply_filters( 'news_revolution_banner_section_args', $editor_args );

news_revolution_render_banner_section( $main_banner_args, $editor_args );

/**
 * Render Banner Section.
 */
function news_revolution_render_banner_section( $main_banner_args, $editor_args ) {
	?>

	<section id="news_revolution_banner_section" class="magazine-banner section-splitter banner-style-1">
		<?php
		if ( is_customize_preview() ) :
			news_revolution_section_link( 'news_revolution_banner_section' );
		endif;
		?>
		<div class="section-wrapper">
			<div class="banner-container-wrapper">

				<div class="banner-wrapper">
					<?php
					require get_template_directory() . '/template-parts/sections/banner/main-banner.php';
					require get_template_directory() . '/template-parts/sections/banner/editors-choice.php';
					?>
				</div>

			</div>
		</div>
	</section>

	<?php

}
