<?php
/**
 * File Path: includes/shortcodes/class-mbs-shortcode-genre-cloud.php
 *
 * [mbs_genre_cloud] Shortcode — Story 13-9
 *
 * Thin shortcode wrapper; all rendering logic lives in
 * MBS_Widget_Genre_Cloud::render_cloud() so the widget and shortcode
 * share a single code path.
 *
 * Usage:
 *   [mbs_genre_cloud]
 *   [mbs_genre_cloud min_count="2" limit="20" min_size="10" max_size="28"]
 *
 * Attributes:
 *   min_size  (int) — smallest font size in px; default 12
 *   max_size  (int) — largest  font size in px; default 22
 *   min_count (int) — hide genres with fewer books; default 1
 *   limit     (int) — max genres shown (0 = unlimited); default 30
 *
 * @package    My_Book_Showroom
 * @subpackage Includes/Shortcodes
 * @since      1.0.0
 */

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

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

	/**
	 * Render the [mbs_genre_cloud] shortcode.
	 *
	 * @param array $atts Raw shortcode attributes.
	 * @return string
	 */
	public static function render( $atts = array() ): string {
		if ( ! mbs_is_registered() ) {
			return '<!-- MBS: License required for [mbs_genre_cloud] -->';
		}

		$atts = shortcode_atts(
			array(
				'min_size'  => 12,
				'max_size'  => 22,
				'min_count' => 1,
				'limit'     => 30,
			),
			$atts,
			'mbs_genre_cloud'
		);

		// Cast to int so render_cloud() receives clean values.
		$atts['min_size']  = (int) $atts['min_size'];
		$atts['max_size']  = (int) $atts['max_size'];
		$atts['min_count'] = (int) $atts['min_count'];
		$atts['limit']     = (int) $atts['limit'];

		$cloud = MBS_Widget_Genre_Cloud::render_cloud( $atts );

		if ( '' === $cloud ) {
			return '<!-- MBS: No genres found for [mbs_genre_cloud] -->';
		}

		return '<div class="mbs-wrapper mbs-genre-cloud-wrapper">' . $cloud . '</div>';
	}
}
