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

$rising_news_main_news_content_ids      = $rising_news_featured_news_content_ids = array();
$rising_news_main_content_type          = get_theme_mod( 'rising_news_main_news_content_type', 'post' );
$rising_news_featured_news_content_type = get_theme_mod( 'rising_news_featured_news_content_type', 'post' );

if ( $rising_news_main_content_type === 'post' ) {
	for ( $rising_news_i = 1; $rising_news_i <= 6; $rising_news_i++ ) {
		$rising_news_main_news_content_ids[] = get_theme_mod( 'rising_news_main_news_content_post_' . $rising_news_i );
	}
	$rising_news_main_news_args = array(
		'post_type'           => 'post',
		'posts_per_page'      => absint( 6 ),
		'ignore_sticky_posts' => true,
	);
	if ( ! empty( array_filter( $rising_news_main_news_content_ids ) ) ) {
		$rising_news_main_news_args['post__in'] = array_filter( $rising_news_main_news_content_ids );
		$rising_news_main_news_args['orderby']  = 'post__in';
	} else {
		$rising_news_main_news_args['orderby'] = 'date';
	}
} else {
	$rising_news_cat_content_id = get_theme_mod( 'rising_news_main_news_content_category' );
	$rising_news_main_news_args = array(
		'cat'            => $rising_news_cat_content_id,
		'posts_per_page' => absint( 6 ),
	);
}
$rising_news_main_news_args = apply_filters( 'rising_news_banner_section_args', $rising_news_main_news_args );

if ( $rising_news_featured_news_content_type === 'post' ) {
	for ( $rising_news_i = 1; $rising_news_i <= 2; $rising_news_i++ ) {
		$rising_news_featured_news_content_ids[] = get_theme_mod( 'rising_news_featured_news_content_post_' . $rising_news_i );
	}
	$rising_news_featured_news_args = array(
		'post_type'           => 'post',
		'posts_per_page'      => absint( 2 ),
		'ignore_sticky_posts' => true,
	);
	if ( ! empty( array_filter( $rising_news_featured_news_content_ids ) ) ) {
		$rising_news_featured_news_args['post__in'] = array_filter( $rising_news_featured_news_content_ids );
		$rising_news_featured_news_args['orderby']  = 'post__in';
	} else {
		$rising_news_featured_news_args['orderby'] = 'date';
	}
} else {
	$rising_news_cat_content_id     = get_theme_mod( 'rising_news_featured_news_content_category' );
	$rising_news_featured_news_args = array(
		'cat'            => $rising_news_cat_content_id,
		'posts_per_page' => absint( 2 ),
	);
}
$rising_news_featured_news_args = apply_filters( 'rising_news_banner_section_args', $rising_news_featured_news_args );

rising_news_render_banner_section( $rising_news_main_news_args, $rising_news_featured_news_args );

/**
 * Render Banner Section.
 */
function rising_news_render_banner_section( $rising_news_main_news_args, $rising_news_featured_news_args ) {
	?>

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

				<?php

				require get_template_directory() . '/template-parts/sections/banner/featured-posts.php';

				require get_template_directory() . '/template-parts/sections/banner/main-banner.php';

				?>

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

	<?php
}
