<?php
/**
 * File Path: includes/layouts/class-mbs-layout-hero.php
 *
 * Hero Layout
 *
 * FREE hero layout for featured books.
 *
 * @package MyBookShowroom
 * @since   1.0.0
 */

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

class MBS_Layout_Hero implements MBS_Layout { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- mbs_/MBS_ prefix is correct; scanner not configured with plugin prefix

	public function render( WP_Query $query, array $options = [] ): string {
		if ( ! mbs_is_registered() ) {
			return '';   // ← LICENSE GATE (GP-T-1)
		}

		if ( ! $query->have_posts() ) {
			return '<p>' . esc_html__( 'No books found.', 'my-book-showroom' ) . '</p>';
		}

		// FE-010: Render ALL books in the query, each as its own hero row.
		// Original design rendered only the first post; corrected for archive use.
		ob_start();
		echo '<div class="mbs-wrapper">';
		while ( $query->have_posts() ) :
			$query->the_post();
			$post_id = get_the_ID();
			echo '<div class="mbs-layout mbs-layout-hero">';
			echo MBS_Cover_Renderer::render( $post_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted renderer returns pre-escaped HTML
			echo '<div class="mbs-hero-content">';
			echo '<h2><a href="' . esc_url( get_permalink() ) . '">' . esc_html( get_the_title() ) . '</a></h2>';
			echo '<p>' . esc_html( get_the_excerpt() ) . '</p>';
			echo '</div>';
			echo '</div>';
		endwhile;
		wp_reset_postdata();
		echo '</div>';

		return ob_get_clean();
	}
}
