<?php
/**
 * Partial template to display the single post's navigation.
 *
 * @package Blogbuster
 *
 */

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

$prev_post = get_previous_post();
$next_post = get_next_post();
if ( $prev_post || $next_post ) {
?>
<nav class="navigation post-navigation" aria-label="Post navigation">
	<h2 class="screen-reader-text"><?php esc_html_e( 'Post navigation', 'blogbuster' ); ?></h2>
	<div class="nav-links">
		<?php
			if ( $prev_post ) {
				$prev_thumb = get_the_post_thumbnail( $prev_post->ID, 'thumbnail' ); // Get thumbnail
				$prev_link 	= get_permalink( $prev_post->ID ); // Get post link
				$prev_title = get_the_title( $prev_post->ID ); // Get post title
				$thumb_class = $prev_thumb ? 'has-thumbnail' : 'no-thumbnail';
		?>
			<div class="nav-previous <?php echo esc_attr( $thumb_class ); ?>">
				<a href="<?php echo esc_url( $prev_link ); ?>" rel="prev">
					<div class="nav-thumbnail"><?php echo $prev_thumb; ?></div><!-- .nav-thumbnail -->
					<div class="nav-content">
						<span class="nav-subtitle"><?php esc_html_e( 'Previous:', 'blogbuster' ); ?></span>
						<span class="nav-title"><?php echo esc_html( $prev_title ); ?></span>
					</div><!-- .nav-content -->
				</a>
			</div><!-- .nav-previous -->
		<?php
			}

			if ( $next_post ) {
				$next_thumb = get_the_post_thumbnail( $next_post->ID, 'thumbnail' ); // Get thumbnail
		        $next_link 	= get_permalink( $next_post->ID ); // Get post link
		        $next_title = get_the_title( $next_post->ID ); // Get post title
		        $thumb_class = $next_thumb ? 'has-thumbnail' : 'no-thumbnail';
		?>
				<div class="nav-next <?php echo esc_attr( $thumb_class ); ?>">
					<a href="<?php echo esc_url( $next_link ); ?>" rel="next">
						<div class="nav-content">
							<span class="nav-subtitle"><?php esc_html_e( 'Next:', 'blogbuster' ); ?></span>
							<span class="nav-title"><?php echo esc_html( $next_title ); ?></span>
						</div><!-- .nav-content -->
						<div class="nav-thumbnail"><?php echo $next_thumb; ?></div><!-- .nav-thumbnail -->

					</a>
				</div><!-- .nav-next -->
		<?php } ?>
	</div><!-- .nav-links -->
</nav>
<?php
}