<?php
/**
 * File Path: includes/blocks/class-mbs-block-author.php
 *
 * Author Block — Render
 *
 * PHP render_callback for the mbs/author Gutenberg block.
 * Registered by MBS_Blocks_Registry::register_author_block().
 *
 * Renders the author bio, social links, optional PRO hero image, and book grid.
 * Delegates entirely to MBS_Shortcode_Author::render() — zero duplicate
 * business logic. All PRO gates are inherited from the shortcode.
 *
 * Attributes:
 *   slug     (string) — Term slug for mbs_author. 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_Author { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- mbs_/MBS_ prefix is correct; scanner not configured with plugin prefix

	/**
	 * Render the Author 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 '';
		}

		$layout = sanitize_key( $attributes['layout'] ?? 'grid' );

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