<?php
/**
 * File Path: includes/blocks/class-mbs-block-genre.php
 *
 * Genre Block — Render
 *
 * PHP render_callback for the mbs/genre Gutenberg block.
 * Registered by MBS_Blocks_Registry::register_genre_block().
 *
 * Renders the genre description and book grid.
 * Delegates entirely to MBS_Shortcode_Genre::render() — zero duplicate
 * business logic. All PRO gates are inherited from the shortcode.
 *
 * Attributes:
 *   slug     (string) — Term slug for mbs_genre. 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_Genre { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- mbs_/MBS_ prefix is correct; scanner not configured with plugin prefix

	/**
	 * Render the Genre 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_Genre::render( array(
			'slug'     => $slug,
			'per_page' => (int) ( $attributes['per_page'] ?? 20 ),
		) );
	}
}
