<?php
/**
 * Displays the next and previous post navigation in single posts.
 */

/**
 * Check whether the 'show_post_navigation' option is activated in the Customizer.
 */
$show_post_navigation = get_theme_mod( 'show_post_navigation', true );

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

$next_post = get_next_post();
$prev_post = get_previous_post();

if ( $next_post || $prev_post ) {

	$pagination_classes = '';

	if ( ! $next_post ) {
		$pagination_classes = ' only-one only-prev';
	} elseif ( ! $prev_post ) {
		$pagination_classes = ' only-one only-next';
	}

	?>

	<nav class="post-navigation-wrapper uk-link-text <?php echo esc_attr( $pagination_classes ); ?>" aria-label="<?php esc_attr_e( 'Post', 'eisai' ); ?>" role="navigation">

		<div class="post-navigation">

			<?php
			if ( $prev_post ) {
				?>

				<a class="previous-post uk-h2" href="<?php echo esc_url( get_permalink( $prev_post->ID ) ); ?>">
					<span class="arrow" aria-hidden="true" data-uk-icon="icon: eisai-arrow-left"></span>
					<span class="title">
						<?php echo wp_kses_post( get_the_title( $prev_post->ID ) ); ?>
					</span>
				</a>

				<?php
			}

			if ( $next_post ) {
				?>

				<a class="next-post uk-h2" href="<?php echo esc_url( get_permalink( $next_post->ID ) ); ?>">
					<span class="arrow" aria-hidden="true" data-uk-icon="icon: eisai-arrow-right"></span>
					<span class="title">
						<?php echo wp_kses_post( get_the_title( $next_post->ID ) ); ?>
					</span>
				</a>
				<?php
			}
			?>

		</div><!-- .post-navigation -->

	</nav><!-- .post-navigation-wrapper -->

	<?php
}
