<?php
/**
 * File Path: includes/blocks/class-mbs-block-author-directory.php
 *
 * Author Directory Block — Render
 *
 * PHP render_callback for the mbs/author-directory Gutenberg block.
 * Registered by MBS_Blocks_Registry::register_author_directory_block().
 *
 * Renders a full author grid with optional bio snippets, book counts,
 * website links, A-Z filter strip, and featured-first ordering.
 * Delegates to MBS_Shortcode_Author_Directory::render(). PRO-gated.
 *
 * Attributes mirror [mbs_author_directory] shortcode params.
 *
 * @package    My_Book_Showroom
 * @subpackage Includes/Blocks
 * @since      1.0.0
 */

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

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

	public static function render( array $attributes ): string {
		if ( ! mbs_is_registered() ) {
			return '';
		}
		// PRO gate is enforced inside MBS_Shortcode_Author_Directory::render();
		// it returns an HTML comment on the FREE tier per plugin spec.

		return MBS_Shortcode_Author_Directory::render( array(
			'columns'             => max( 1, min( 6, (int) ( $attributes['columns']             ?? 3   ) ) ),
			'show_count'          => ! empty( $attributes['show_count']          ?? true  ),
			'show_bio'            => ! empty( $attributes['show_bio']            ?? true  ),
			'bio_length'          => max( 20, (int) ( $attributes['bio_length']   ?? 120  ) ),
			'show_website'        => ! empty( $attributes['show_website']        ?? true  ),
			'show_featured_first' => ! empty( $attributes['show_featured_first'] ?? true  ),
			'show_filter'         => ! empty( $attributes['show_filter']         ?? true  ),
			'orderby'             => sanitize_key( $attributes['orderby']         ?? 'name'       ),
			'order'               => in_array( $attributes['order'] ?? 'ASC', array( 'ASC', 'DESC' ), true )
									   ? $attributes['order'] : 'ASC',
			'sort'                => in_array( $attributes['sort'] ?? 'first_name', array( 'first_name', 'last_name', 'name_sort' ), true )
									   ? $attributes['sort'] : 'first_name',
		) );
	}
}
