<?php
/**
 * File Path: includes/blocks/class-mbs-block-endorsements.php
 *
 * Endorsements Block -- Render
 *
 * PHP render_callback for the mbs/endorsements Gutenberg block.
 * Registered by MBS_Blocks_Registry::register_endorsements_block().
 *
 * Renders the endorsements/blurbs list for a book, delegating to
 * templates/partials/section-endorsements.php via mbs_get_template_part().
 * Returns empty string when the book has no endorsements. FREE tier.
 *
 * Attributes:
 *   bookId (number) -- Book post ID. Default 0 (none selected).
 *
 * @package    My_Book_Showroom
 * @subpackage Includes/Blocks
 * @since      1.0.0
 */

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

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

	public static function render( array $attributes ): string {
		if ( ! mbs_is_registered() ) {
			return '';
		}

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

		ob_start();
		mbs_get_template_part( 'partials/section-endorsements', array( 'post_id' => $post_id ) );
		return ob_get_clean();
	}
}
