<?php
/**
 * File Path: includes/blocks/class-mbs-block-collection.php
 *
 * Collection Block — Render
 *
 * PHP render_callback for the mbs/collection Gutenberg block.
 * Registered by MBS_Blocks_Registry::register_collection_block().
 *
 * Renders the collection type label, description, optional PRO reading order, and book grid.
 * Delegates entirely to MBS_Shortcode_Collection::render() — zero duplicate
 * business logic. All PRO gates are inherited from the shortcode.
 *
 * Attributes:
 *   slug     (string) — Term slug for mbs_collection. Required.
 *   per_page (number) — Books per page in the book grid. -1 = all. Default 20.
 *
 * License gate: mbs_is_registered() — returns empty string when false.
 *
 * @package    My_Book_Showroom
 * @subpackage Includes/Blocks
 * @since      1.0.0
 */

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

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

	/**
	 * Render the Collection block.
	 *
	 * @param array $attributes Block attributes from the editor.
	 * @return string Rendered HTML.
	 */
	public static function render( array $attributes ): string {
		if ( ! mbs_is_registered() ) {
			return '';
		}

		$slug = sanitize_title( $attributes['slug'] ?? '' );
		if ( '' === $slug ) {
			return '';
		}

		return MBS_Shortcode_Collection::render( array(
			'slug'     => $slug,
			'per_page' => (int) ( $attributes['per_page'] ?? 20 ),
		) );
	}
}
