<?php
/**
 * Partial template for banner slider timeline.
 *
 * @package Purenote
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

$purenote_banner_timeline_title = purenote_get_customizer_option_value( 'purenote_banner_timeline_title' );

$purenote_timeline_args = array();

if ( isset( $args ) && is_array( $args ) && isset( $args['timeline_args'] ) ) {
    $purenote_timeline_args = $args;
} else {
    $purenote_timeline_args = get_query_var( 'purenote_timeline_args', array() );
}

$timeline_args = isset( $purenote_timeline_args['timeline_args'] ) && is_array( $purenote_timeline_args['timeline_args'] ) ? $purenote_timeline_args['timeline_args'] : array();

if ( empty( $timeline_args ) ) {
    $timeline_args = array(
        'posts_per_page'      => 5,
        'orderby'             => 'date',
        'order'               => 'DESC',
        'ignore_sticky_posts' => true,
    );
}

?>
<div class="timeline-wrapper">
    <h2 class="timeline-title">
        <?php echo esc_html( $purenote_banner_timeline_title ); ?> 
    </h2>
    
    <?php
        $timeline_query = new WP_Query( $timeline_args );

        if ( $timeline_query->have_posts() ) :
            while ( $timeline_query->have_posts() ) : $timeline_query->the_post(); ?>
                <div class="single-post-wrapper">
                    <div class="post-thumbnail-wrap">
                        <?php 
                            if ( function_exists( 'purenote_post_thumbnail' ) ) {
                                purenote_post_thumbnail( 'purenote-block-medium' );
                            }
                        ?>
                    </div>
                    <div class="post-title-wrap">
                        <div class="post-cats-wrap">
                            <?php 
                                if ( function_exists( 'purenote_the_post_categories_list' ) ) {
                                    purenote_the_post_categories_list( get_the_ID(), 1 );
                                } 
                            ?>
                        </div>
                        <h2 class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                        <div class="post-date">
                            <?php
                                if ( function_exists( 'purenote_posted_on' ) ) {
                                    purenote_posted_on();
                                }
                            ?>
                        </div>
                    </div>
                </div>
            <?php
                endwhile;
                    wp_reset_postdata();
        else:
        ?>
            <p class="no-posts-found"><?php esc_html_e( 'No trending timeline posts found.', 'purenote' ); ?></p>
    <?php endif; ?>

</div><!-- timeline-wrapper -->