<?php
/**
 * File Path: templates/taxonomy-mbs-tag.php
 *
 * Taxonomy Archive — mbs_tag
 *
 * Displays all books carrying a specific tag (character, setting, trope,
 * content advisor, etc.) with proper license gating, theme override support,
 * and consistent .mbs-wrapper scoping.
 *
 * @package MyBookShowroom
 * @since   1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! mbs_is_registered() ) {
	get_header();
	echo '<p>' . esc_html__( 'This feature requires a registered license.', 'my-book-showroom' ) . '</p>';
	get_footer();
	exit;
}

get_header();

$term = get_queried_object();
?>

<div class="mbs-wrapper mbs-taxonomy-archive mbs-taxonomy-archive-tag">
	<header class="mbs-archive-header">
		<h1 class="mbs-archive-title">
			<?php
			printf(
				/* translators: %s: tag name */
				esc_html__( 'Tag: %s', 'my-book-showroom' ),
				esc_html( single_term_title( '', false ) )
			);
			?>
		</h1>
		<?php if ( $term instanceof WP_Term && ! empty( $term->description ) ) : ?>
			<div class="mbs-term-description">
				<?php echo wp_kses_post( wpautop( $term->description ) ); ?>
			</div>
		<?php endif; ?>
	</header>

	<?php if ( have_posts() ) : ?>
		<div class="mbs-book-grid">
			<?php
			while ( have_posts() ) :
				the_post();
				mbs_get_template_part( 'partials/book-card' );
			endwhile;
			?>
		</div>

		<?php
		the_posts_pagination( array(
			'mid_size'  => 2,
			'prev_text' => __( '← Previous', 'my-book-showroom' ),
			'next_text' => __( 'Next →', 'my-book-showroom' ),
		) );
		?>
	<?php else : ?>
		<p><?php esc_html_e( 'No books found with this tag.', 'my-book-showroom' ); ?></p>
	<?php endif; ?>
</div>

<?php
mbs_get_template_part( 'partials/power-badge' );
get_footer();
