<?php
/**
 * File Path: includes/blocks/class-mbs-block-esp-signup.php
 *
 * Block: mbs/esp-signup (PRO)
 *
 * PHP render_callback for the mbs/esp-signup Gutenberg block.
 * Delegates to MBS_ESP_Widget::render() so block and shortcode
 * output are always identical. PRO-gated. Settings-driven.
 *
 * Attributes:
 *   bookId           (int,     default 0)     -- Optional book context (0 = page context).
 *   showConsentField (boolean, default true)  -- Show GDPR consent checkbox.
 *   buttonLabel      (string,  default 'Subscribe') -- CTA button text.
 *
 * @package    My_Book_Showroom
 * @subpackage Includes/Blocks
 * @since      1.0.0
 */

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

/**
 * Class MBS_Block_Esp_Signup
 *
 * Render callback for the mbs/esp-signup Gutenberg block.
 *
 * @since 1.0.0
 */
class MBS_Block_Esp_Signup { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- mbs_/MBS_ prefix is correct; scanner not configured with plugin prefix

	/**
	 * Render the mbs/esp-signup block.
	 *
	 * @param array $attributes Block attribute values.
	 * @return string Rendered HTML or HTML comment on non-PRO installs.
	 */
	public static function render( array $attributes ): string {
		if ( ! mbs_is_pro() ) {
			return '<!-- MBS: esp-signup requires PRO license -->';
		}

		// MBS_ESP_Widget::render() is settings-driven; bookId provides optional post context.
		$book_id = max( 0, (int) ( $attributes['bookId'] ?? 0 ) );

		if ( ! class_exists( 'MBS_ESP_Widget' ) ) {
			/* translators: Block placeholder when MBS_ESP_Widget class is unavailable. */
			return '<p class="mbs-block-notice">' . esc_html__( 'ESP Signup is not available. Please check your My Book Showroom installation.', 'my-book-showroom' ) . '</p>';
		}

		return MBS_ESP_Widget::render( $book_id );
	}
}
