<?php
/**
 * File Path: includes/admin/tabs/appearance/class-mbs-appearance-colors-render.php
 *
 * Appearance Tab — Colors Render Class (free + PRO)
 *
 * Called statically from MBS_Tab_Appearance_Render dispatcher.
 * Extracted from class-mbs-tab-appearance-render.php (RF-009).
 *
 * @package MyBookShowroom
 * @since   1.0.0
 */

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

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

	/**
	 * Render the FREE Accent Colors section.
	 *
	 * @return void
	 */
	/**
	 * Render the FREE Accent Colors section — 4-picker grid.
	 *
	 * @return void
	 */
	public static function render_free_colors(): void {
		$free_fields = array(
			array( 'accent',      __( 'Primary Accent',    'my-book-showroom' ) ),
			array( 'button_bg',   __( 'Button Background', 'my-book-showroom' ) ),
			array( 'button_text', __( 'Button Text',       'my-book-showroom' ) ),
			array( 'link',        __( 'Link Color',        'my-book-showroom' ) ),
		);
		?>
		<div class="mbs-appearance-section mbs-settings-card">
			<h3><?php esc_html_e( 'Accent Colors (FREE)', 'my-book-showroom' ); ?></h3>
			<div class="mbs-color-grid">
				<?php foreach ( $free_fields as $field ) :
					list( $key, $label ) = $field;
					$field_id   = 'mbs_appearance_' . $key;
					$option_key = 'mbs_setting_appearance_' . $key;
					$default    = MBS_Tab_Appearance::FREE_DEFAULTS[ $key ];
				?>
				<div class="mbs-color-cell">
					<label for="<?php echo esc_attr( $field_id ); ?>"><?php echo esc_html( $label ); ?></label>
					<input type="text"
					       id="<?php echo esc_attr( $field_id ); ?>"
					       name="<?php echo esc_attr( $option_key ); ?>"
					       value="<?php echo esc_attr( mbs_get_setting( 'appearance', $key, $default ) ); ?>"
					       class="mbs-color-picker"
					       data-default-color="<?php echo esc_attr( $default ); ?>">
				</div>
				<?php endforeach; ?>
			</div>
		</div>
		<?php
	}

	/**
	 * Render the PRO Colors section. Internalizes the PRO check (RF-009).
	 *
	 * @return void
	 */
	/**
	 * Render the PRO Colors section — upgrade notice (FREE) or 16-token
	 * grouped grid in three semantic groups (PRO).
	 *
	 * C-001: All 16 token keys match the D-2 canonical names read by
	 * mbs_output_color_vars(). Grouped semantically so the 4-column layout
	 * preserves meaningful adjacency within each group.
	 *
	 * @param bool $is_pro Whether the current install is PRO tier.
	 * @return void
	 */
	public static function render(): void {
		$is_pro = mbs_is_pro();
		$pro_groups = array(
			array(
				'label'  => __( 'Structural Palette', 'my-book-showroom' ),
				'fields' => array(
					array( 'navy',          __( 'Navy',          'my-book-showroom' ), '#2C3E6B', __( 'Used on: Reader Signup Widget text',                         'my-book-showroom' ) ),
					array( 'navy_dark',     __( 'Navy Dark',     'my-book-showroom' ), '#1A2B50', __( 'Used on: Author name links; filter button hover text',       'my-book-showroom' ) ),
					array( 'lavender',      __( 'Lavender',      'my-book-showroom' ), '#C8B4D4', __( 'Used on: Theme Pill border',                                 'my-book-showroom' ) ),
					array( 'teal_pale',     __( 'Teal Pale',     'my-book-showroom' ), '#D4EEF1', __( 'Used on: Author Directory filter button hover background',   'my-book-showroom' ) ),
					array( 'lavender_pale', __( 'Lavender Pale', 'my-book-showroom' ), '#EDE8F4', __( 'Used on: Theme Pill background',                             'my-book-showroom' ) ),
					array( 'beige',         __( 'Beige',         'my-book-showroom' ), '#F4F0E8', __( 'Used on: Reader Signup Widget surface',                      'my-book-showroom' ) ),
					array( 'slate',         __( 'Slate',         'my-book-showroom' ), '#5A6472', __( 'Used on: Author Directory filter button text',               'my-book-showroom' ) ),
					array( 'mist',          __( 'Mist',          'my-book-showroom' ), '#9AABBA', __( 'Used on: Author photo placeholder background',               'my-book-showroom' ) ),
				),
			),
			array(
				'label'  => __( 'Badges & Pills', 'my-book-showroom' ),
				'fields' => array(
					array( 'pro_bg',          __( 'PRO Tier Pill Background',  'my-book-showroom' ), '#EDE8F4' ),
					array( 'pro_text',        __( 'PRO Tier Pill Text',        'my-book-showroom' ), '#5A3A72' ),
					array( 'coming_soon_bg',  __( 'Coming Soon Background',    'my-book-showroom' ), '#F59E0B' ),
					array( 'coming_soon_text', __( 'Coming Soon Text',         'my-book-showroom' ), '#FFFFFF' ),
				),
			),
			array(
				'label'  => __( 'Card & Accessories', 'my-book-showroom' ),
				'fields' => array(
					array( 'card_bg',        __( 'Card Background', 'my-book-showroom' ), '#FFFFFF' ),
					array( 'border',         __( 'Border',          'my-book-showroom' ), '#E0D8C8' ),
					array( 'watermark_text', __( 'Watermark Text',  'my-book-showroom' ), '#9AABBA' ),
					array( 'star',           __( 'Star Rating',     'my-book-showroom' ), '#F5A623' ),
				),
			),
		);
		?>
		<div class="mbs-appearance-section mbs-settings-card">
			<h3><?php echo $is_pro ? esc_html__( 'Advanced Colors', 'my-book-showroom' ) : esc_html__( 'Advanced Colors (PRO)', 'my-book-showroom' ); ?></h3>
			<?php if ( ! $is_pro ) : ?>
				<p><strong><?php esc_html_e( 'PRO Feature:', 'my-book-showroom' ); ?></strong>
					<?php esc_html_e( 'Unlock 16 additional color tokens with a PRO license.', 'my-book-showroom' ); ?></p>
			<?php else : ?>
				<?php foreach ( $pro_groups as $group ) : ?>
					<h4 class="mbs-color-group-label"><?php echo esc_html( $group['label'] ); ?></h4>
					<div class="mbs-color-grid">
						<?php foreach ( $group['fields'] as $field ) :
							$key        = $field[0];
							$label      = $field[1];
							$default    = $field[2];
							$field_desc = isset( $field[3] ) ? $field[3] : '';
							$field_id   = 'mbs_appearance_' . $key;
							$option_key = 'mbs_setting_appearance_' . $key;
						?>
						<div class="mbs-color-cell">
							<label for="<?php echo esc_attr( $field_id ); ?>"><?php echo esc_html( $label ); ?></label>
							<?php if ( $field_desc ) : ?>
							<p class="description mbs-token-hint"><?php echo esc_html( $field_desc ); ?></p>
							<?php endif; ?>
							<input type="text"
							       id="<?php echo esc_attr( $field_id ); ?>"
							       name="<?php echo esc_attr( $option_key ); ?>"
							       value="<?php echo esc_attr( mbs_get_setting( 'appearance', $key, $default ) ); ?>"
							       class="mbs-color-picker mbs-pro-color-picker"
							       data-default-color="<?php echo esc_attr( $default ); ?>">
						</div>
						<?php endforeach; ?>
					</div>
				<?php endforeach; ?>
			<?php endif; ?>
		</div>
		<?php
	}

}
