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

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