<?php
/**
 * File Path: templates/admin/metabox-categorization.php
 *
 * Tags & Themes Metabox Template Partial
 *
 * Loaded by MBS_Metabox_Categorization::render() via mbs_get_template_part().
 *
 * Injected variables:
 *   array $tabs  Tab config: id, label, terms, assigned, field, taxonomy, empty.
 *                Contains two entries: Tags (mbs_tag) and Themes (mbs_theme).
 *
 * Content Warnings, BISAC, Bowker, Audience, Age Range, and Grade Range
 * are rendered by templates/admin/metabox-classification.php (CLASS-6).
 *
 * @package    My_Book_Showroom
 * @subpackage Templates/Admin
 * @since      1.0.0
 */

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

wp_nonce_field( 'mbs_save_categorization', 'mbs_categorization_nonce' );
?>
<div class="mbs-cat-metabox">

	<!-- Tab navigation -->
	<div class="mbs-cat-tabs" role="tablist">
		<?php foreach ( $tabs as $i => $tab ) : // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variable; not a global?>
			<button type="button"
			        class="mbs-cat-tab-btn<?php echo 0 === $i ? ' mbs-cat-tab-btn--active' : ''; ?>"
			        data-tab="<?php echo esc_attr( $tab['id'] ); ?>"
			        role="tab"
			        aria-selected="<?php echo 0 === $i ? 'true' : 'false'; ?>"
			        aria-controls="mbs-cat-panel-<?php echo esc_attr( $tab['id'] ); ?>">
				<?php echo esc_html( $tab['label'] ); ?>
			</button>
		<?php endforeach; ?>
	</div>

	<!-- Tab panels -->
	<?php foreach ( $tabs as $i => $tab ) : // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template-scope variable; not a global?>
		<div id="mbs-cat-panel-<?php echo esc_attr( $tab['id'] ); ?>"
		     class="mbs-cat-panel<?php echo 0 === $i ? ' mbs-cat-panel--active' : ''; ?>"
		     role="tabpanel">

			<?php if ( empty( $tab['terms'] ) ) : ?>
				<p class="mbs-cat-empty"><?php echo esc_html( $tab['empty'] ); ?></p>
			<?php else : ?>
				<ul class="mbs-cat-checklist">
					<?php foreach ( $tab['terms'] as $term ) : ?>
						<li>
							<label>
								<input type="checkbox"
								       name="<?php echo esc_attr( $tab['field'] ); ?>[]"
								       value="<?php echo esc_attr( $term->term_id ); ?>"
								       <?php checked( in_array( $term->term_id, $tab['assigned'], true ) ); ?>>
								<?php echo esc_html( $term->name ); ?>
							</label>
						</li>
					<?php endforeach; ?>
				</ul>
			<?php endif; ?>
		</div>
	<?php endforeach; ?>

</div>
