<?php
/**
 * Main Banner template three
 * 
 * @package One Newspaper
 * @since 1.0.0
 */
use OneNewspaper\CustomizerDefault as ONP;
$slider_args = $args['slider_args'];
$main_banner_slider_categories_option = ONP\one_newspaper_get_customizer_option( 'main_banner_slider_categories_option' );
$main_banner_slider_date_option = ONP\one_newspaper_get_customizer_option( 'main_banner_slider_date_option' );
?>
<div class="main-banner-wrap">
    <div class="main-banner-slider one-newspaper-card">
        <?php
            $slider_query = new WP_Query( $slider_args );
            if( $slider_query -> have_posts() ) :
                while( $slider_query -> have_posts() ) : $slider_query -> the_post();
                ?>
                    <article class="slide-item<?php if(!has_post_thumbnail()){ echo esc_attr(' no-feat-img');} ?>">
                        <figure class="post-thumb">
                            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                                <?php 
                                    if( has_post_thumbnail()) { 
                                        the_post_thumbnail('one-newspaper-featured', array(
                                            'title' => the_title_attribute(array(
                                                'echo'  => false
                                            ))
                                        ));
                                    }
                                ?>
                            </a>
                        </figure>
                        <div class="post-element">
                            <div class="post-meta">
                                <?php 
                                    if( $main_banner_slider_categories_option ) one_newspaper_get_post_categories( get_the_ID(), 2 );
                                    if( $main_banner_slider_date_option ) one_newspaper_posted_on();
                                ?>
                            </div>
                            <h2 class="post-title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                        </div>
                    </article>
                <?php
                endwhile;
            endif;
        ?>
    </div>
</div>

<div class="main-banner-block-posts banner-trailing-posts">
    <?php
        $main_banner_block_posts_to_include = ONP\one_newspaper_get_customizer_option( 'main_banner_block_posts_to_include' );
        $main_banner_block_posts_categories = ONP\one_newspaper_get_customizer_option( 'main_banner_block_posts_categories' );
        $main_banner_block_posts_order_by = ONP\one_newspaper_get_customizer_option( 'main_banner_block_posts_order_by' );
        $main_banner_block_posts_numbers = ONP\one_newspaper_get_customizer_option( 'main_banner_block_posts_numbers' );
        $blockPostsOrderArray = explode( '-', $main_banner_block_posts_order_by );
        $block_posts_args = array(
            'numberposts' => ( $main_banner_block_posts_numbers < 3 ) ? absint( $main_banner_block_posts_numbers ) : 3,
            'order' => esc_html( $blockPostsOrderArray[1] ),
            'orderby' => esc_html( $blockPostsOrderArray[0] ),
            'cat' => one_newspaper_get_categories_for_args($main_banner_block_posts_categories)
        );
        if( ! empty( $main_banner_block_posts_to_include ) ) $block_posts_args['post__in'] = one_newspaper_get_post_id_for_args( $main_banner_block_posts_to_include ); 
        $block_posts = get_posts( $block_posts_args );
        if( $block_posts ) :
            $main_banner_block_posts_categories_option = ONP\one_newspaper_get_customizer_option( 'main_banner_block_posts_categories_option' );
            foreach( $block_posts as $popular_post ) :
                $popular_post_id  = $popular_post->ID;
            ?>
                    <article class="post-item one-newspaper-card<?php if(!has_post_thumbnail($popular_post_id)){ echo esc_attr(' no-feat-img');} ?>">
                        <figure class="post-thumb">
                            <?php if( has_post_thumbnail($popular_post_id) ): ?>
                                <a href="<?php echo esc_url(get_the_permalink($popular_post_id)); ?>" title="<?php the_title_attribute(['post' => $popular_post_id]); ?>">
                                    <img src="<?php echo esc_url( get_the_post_thumbnail_url($popular_post_id, 'one-newspaper-featured') ); ?>" alt="<?php echo esc_attr( get_post_meta( get_post_thumbnail_id($popular_post_id), '_wp_attachment_image_alt', true ) ); ?>"/>
                                </a>
                            <?php endif; ?>
                        </figure>
                        <div class="post-element">
                            <?php if( $main_banner_block_posts_categories_option ) : ?>
                                    <div class="post-meta">
                                        <?php one_newspaper_get_post_categories( $popular_post_id, 2 ); ?>
                                    </div>
                            <?php endif; ?>
                            <h2 class="post-title"><a href="<?php the_permalink($popular_post_id); ?>"><?php echo wp_kses_post( get_the_title($popular_post_id) ); ?></a></h2>
                        </div>
                    </article>
            <?php
            endforeach;
        endif;
    ?>
</div>