<?php
/**
 * Post Navigation Template.
 *
 * Displays links to the previous and next posts
 * in a styled wrapper for single post templates.
 *
 * @package    Wira
 * @since      1.0.0
 */

namespace Wira\Templates;

if ( ! class_exists( 'Post_Navigation' ) ) {

	/**
	 * Post_Navigation Class.
	 *
	 * Handles rendering of previous and next post links.
	 *
	 * @since 1.0.0
	 */
	class Post_Navigation {

		/**
		 * Render post navigation.
		 *
		 * Outputs a navigation wrapper with links to
		 * the previous and next posts if available.
		 *
		 * @since 1.0.0
		 * @return void
		 */
		public function render() {
			$prev_post = get_previous_post();
			$next_post = get_next_post();

			// Bail early if no adjacent posts exist.
			if ( empty( $prev_post ) && empty( $next_post ) ) {
				return;
			}

			// Main wrapper.
			echo '<div class="post-navigation d-flex justify-content-between">';

			// Previous post link.
			echo '<div class="prev-post text-start">';
			if ( ! empty( $prev_post ) ) {
				echo '<a href="' . esc_url( get_permalink( $prev_post->ID ) ) . '">';
				echo '<span class="theme-text-small theme-color-placeholder d-block mb-1">← ' . esc_html__( 'Previous Post', 'wira' ) . '</span>';
				echo '<strong>' . esc_html( wp_trim_words( get_the_title( $prev_post->ID ), 3 ) ) . '</strong>';
				echo '</a>';
			}
			echo '</div>';

			// Next post link.
			echo '<div class="next-post text-end">';
			if ( ! empty( $next_post ) ) {
				echo '<a href="' . esc_url( get_permalink( $next_post->ID ) ) . '">';
				echo '<span class="theme-text-small theme-color-placeholder d-block mb-1">' . esc_html__( 'Next Post', 'wira' ) . ' →</span>';
				echo '<strong>' . esc_html( wp_trim_words( get_the_title( $next_post->ID ), 3 ) ) . '</strong>';
				echo '</a>';
			}
			echo '</div>';

			echo '</div>'; // .post-navigation
		}
	}
}
