<?php
/**
 * File Path: templates/admin/partials/layout-picker.php
 *
 * Admin Partial — Book Grid Layout Picker
 *
 * Renders the "Book Grid Layout" <select> field used on the Series,
 * Collection, and Universe admin cards. Handles the tier-gated option list,
 * Hero exclusion (F-LYT-1), and the grid-default selection.
 *
 * Expected variables (passed via mbs_get_template_part() $args):
 *   int    $term_id      Term ID — used for the <select> id/name attributes.
 *   string $term_layout  Saved per-term layout slug ('' means use grid default).
 *   string $desc_text    Already-translated description <p> text for this entity.
 *
 * Extracts: DUP-007 (Session 214).
 *
 * @package MyBookShowroom
 * @since   1.1.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variables injected by mbs_get_template_part(); not global vars

if ( ! mbs_is_registered() ) {
	return;
}

$layout_options = MBS_Layout_Registry::get_layout_options();
$show_all       = mbs_is_pro() || mbs_is_pub();
$free_slugs     = MBS_Layout_Registry::get_free_layout_slugs();
?>
<div class="mbs-settings-field-cell">
	<label for="mbs_term_layout_<?php echo esc_attr( $term_id ); ?>">
		<?php esc_html_e( 'Book Grid Layout', 'my-book-showroom' ); ?>
	</label>
	<select name="mbs_term_layout[<?php echo esc_attr( $term_id ); ?>]"
	        id="mbs_term_layout_<?php echo esc_attr( $term_id ); ?>">
		<?php foreach ( $layout_options as $slug => $meta ) : ?>
			<?php if ( ! $show_all && ! in_array( $slug, $free_slugs, true ) ) { continue; } ?>
			<?php if ( 'hero' === $slug ) { continue; } // F-LYT-1: Hero is single-book; not suitable for entity archives. ?>
			<option value="<?php echo esc_attr( $slug ); ?>"
			        <?php selected( $term_layout ?: 'grid', $slug ); ?>>
				<?php echo esc_html( $meta['label'] ); ?>
			</option>
		<?php endforeach; ?>
	</select>
	<p class="description">
		<?php echo esc_html( $desc_text ); ?>
	</p>
</div>
