<?php
/**
 * Template part for displaying front page introduction.
 *
 * @package Hot News
 */

// Banner Section.
$banner_section = get_theme_mod( 'hot_news_banner_section_enable', false );

if ( false === $banner_section ) {
	return;
}

$banner_news_content_ids     = $featured_posts_content_ids = $editor_pick_content_ids = array();
$banner_content_type         = get_theme_mod( 'hot_news_banner_news_content_type', 'post' );
$featured_posts_content_type = get_theme_mod( 'hot_news_featured_posts_content_type', 'post' );
$editor_pick_content_type    = get_theme_mod( 'hot_news_editor_pick_content_type', 'post' );

if ( $banner_content_type === 'post' ) {

	for ( $i = 1; $i <= 3; $i++ ) {
		$banner_news_content_ids[] = get_theme_mod( 'hot_news_banner_news_post_' . $i );
	}

	$banner_args = array(
		'post_type'           => 'post',
		'posts_per_page'      => absint( 3 ),
		'ignore_sticky_posts' => true,
	);

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

} else {
	$cat_content_id = get_theme_mod( 'hot_news_banner_news_category' );
	$banner_args    = array(
		'cat'            => $cat_content_id,
		'posts_per_page' => absint( 3 ),
	);
}

if ( $featured_posts_content_type === 'post' ) {

	for ( $i = 1; $i <= 2; $i++ ) {
		$featured_posts_content_ids[] = get_theme_mod( 'hot_news_featured_posts_post_' . $i );
	}

	$featured_posts_args = array(
		'post_type'           => 'post',
		'posts_per_page'      => absint( 2 ),
		'ignore_sticky_posts' => true,
	);

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

} else {
	$cat_content_id      = get_theme_mod( 'hot_news_featured_posts_category' );
	$featured_posts_args = array(
		'cat'            => $cat_content_id,
		'posts_per_page' => absint( 2 ),
	);
}

if ( $editor_pick_content_type === 'post' ) {

	for ( $i = 1; $i <= 5; $i++ ) {
		$editor_pick_content_ids[] = get_theme_mod( 'hot_news_editor_pick_post_' . $i );
	}

	$editor_pick_args = array(
		'post_type'           => 'post',
		'posts_per_page'      => absint( 5 ),
		'ignore_sticky_posts' => true,
	);
	if ( ! empty( array_filter( $editor_pick_content_ids ) ) ) {
		$editor_pick_args['post__in'] = array_filter( $editor_pick_content_ids );
		$editor_pick_args['orderby']  = 'post__in';
	} else {
		$editor_pick_args['orderby'] = 'date';
	}

} else {
	$cat_content_id  = get_theme_mod( 'hot_news_editor_pick_category' );
	$editor_pick_args = array(
		'cat'            => $cat_content_id,
		'posts_per_page' => absint( 5 ),
	);
}

?>

<div id="hot_news_banner_section" class="main-banner-section style-1 adore-navigation">
	<div class="theme-wrapper">
		<div class="main-banner-section-wrapper">

			<?php
			
			require get_template_directory() . '/inc/frontpage-sections/banner-sections/banner-news.php';
			require get_template_directory() . '/inc/frontpage-sections/banner-sections/banner-featured-posts.php';
			require get_template_directory() . '/inc/frontpage-sections/banner-sections/editor-pick.php';

			?>

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