<?php
/**
 * File Path: includes/blocks/class-mbs-block-single-book.php
 *
 * Single Book Block — Render
 *
 * PHP render_callback for the mbs/single-book Gutenberg block.
 * Registered by MBS_Blocks_Registry::register_single_book_block().
 *
 * Renders the full single-book display: cover, teaser, tab navigation,
 * tabs (This Book, Look Inside, Trailer PRO, More in Series, More by Author),
 * and all section-ordered content (About the Book, Endorsements, Reviews, etc.).
 *
 * Delegates entirely to MBS_Shortcode_Book::render() so block and shortcode
 * share identical output logic. Zero duplicate business logic.
 *
 * Attributes:
 *   bookId (number) — Post ID of the mbs_book post to display. Required.
 *
 * License gates (inherited from MBS_Shortcode_Book::render()):
 *   - mbs_is_registered() — block returns empty string when false.
 *   - mbs_is_pro()        — trailer tab, PRO layouts shown only on PRO/PUB tier.
 *
 * @package    My_Book_Showroom
 * @subpackage Includes/Blocks
 * @since      1.0.0
 */

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

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

	/**
	 * Render the Single Book block.
	 *
	 * Called by WordPress as the register_block_type render_callback.
	 * Returns an empty string when no license is active or no valid book ID
	 * is provided, producing no broken shell in the front-end output.
	 *
	 * @param array $attributes Block attributes from the editor.
	 * @return string Rendered HTML.
	 */
	public static function render( array $attributes ): string {
		if ( ! mbs_is_registered() ) {
			return '';
		}

		$post_id = ! empty( $attributes['bookId'] ) ? (int) $attributes['bookId'] : 0;
		if ( ! $post_id || get_post_type( $post_id ) !== MBS_POST_TYPE ) {
			return '';
		}

		return MBS_Shortcode_Book::render( array( 'id' => $post_id ) );
	}
}
