<?php
/**
 * File Path: includes/admin/tabs/authors-series/class-mbs-tab-catalog-subnav.php
 *
 * Catalog Sub-Navigation
 *
 * Renders the persistent Authors / Series / Collections / Universes pill nav
 * that appears at the top of each entity tab (UX-NAV-001). All four render
 * classes call MBS_Tab_Catalog_Subnav::render() immediately after their
 * opening wrapper div so the nav survives PRG save-redirects and lets the
 * admin move between entity sections without returning to the Catalog index.
 *
 * Universe link visibility rules (both conditions required):
 *   1. mbs_setting_advanced_universe_enabled == 1  (Advanced tab toggle)
 *   2. mbs_is_pro() === true  (PRO or Publisher license; FREE tier excluded)
 *
 * @package    My_Book_Showroom
 * @subpackage Includes/Admin/Tabs/Authors-Series
 * @since      1.4.0
 */

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

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

	/**
	 * Render the catalog sub-navigation bar.
	 *
	 * @param string $active  Slug of the currently active entity tab, or 'catalog'
	 *                        for hub/neutral mode (no item highlighted).
	 *                        Accepts: 'catalog' | 'authors' | 'series' |
	 *                        'collections' | 'universes'.
	 *                        WARNING: do not add 'catalog' as an $items key;
	 *                        its non-match is the mechanism for neutral rendering.
	 * @return void
	 */
	public static function render( string $active ): void {
		$base          = admin_url( 'admin.php?page=my-book-showroom-settings&tab=' );
		$show_universe = mbs_is_pro() && (int) get_option( 'mbs_setting_advanced_universe_enabled', 0 );

		$items = array(
			'authors' => __( 'Authors', 'my-book-showroom' ),
			'series'  => __( 'Series',  'my-book-showroom' ),
		);

		if ( $show_universe ) {
			$items['universes'] = __( 'Universes', 'my-book-showroom' );
		}

		$items['collections'] = __( 'Collections', 'my-book-showroom' );

		$icon_map = array(
			'authors'     => 'entity-authors',
			'series'      => 'entity-series',
			'collections' => 'entity-collections',
			'universes'   => 'entity-universes',
		);
		?>
		<nav class="mbs-catalog-subnav" aria-label="<?php esc_attr_e( 'Catalog sections', 'my-book-showroom' ); ?>">
			<?php foreach ( $items as $slug => $label ) : ?>
				<?php $icon_html = isset( $icon_map[ $slug ] ) ? mbs_icon( $icon_map[ $slug ], array( 'size' => '16px', 'aria_label' => '' ) ) : ''; ?>
				<a href="<?php echo esc_url( $base . $slug ); ?>"
				   class="mbs-catalog-subnav__item<?php echo $active === $slug ? ' mbs-catalog-subnav__item--active' : ''; ?>"
				   <?php echo $active === $slug ? 'aria-current="page"' : ''; ?>>
					<?php echo $icon_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- pre-sanitized by mbs_icon() ?>
					<?php echo esc_html( $label ); ?>
				</a>
			<?php endforeach; ?>
		</nav>
		<?php
	}

}
