<?php
/**
 * File Path: includes/admin/tabs/appearance/class-mbs-appearance-badges-render.php
 *
 * Appearance Tab — Power Badge Render Class
 *
 * 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_Badges_Render { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- mbs_/MBS_ prefix is correct; scanner not configured with plugin prefix

	/**
	 * Render the Power Badge settings section.
	 *
	 * @return void
	 */
	/**
	 * Render the Power Badge settings section.
	 *
	 * Badge Position: available to all registered tiers (FREE+).
	 * Badge Toggle: ALL tiers see this row.
	 *   FREE -- checkbox disabled and locked ON (cannot opt out).
	 *   PRO/PUB -- checkbox enabled, on by default (can opt out).
	 *
	 * @return void
	 */
	public static function render(): void {
		if ( ! mbs_is_pro() ) {
			MBS_Pro_Gate::comment( 'Power Badge settings' );
			return;
		}
		?>
		<div class="mbs-appearance-section mbs-settings-card">
			<h3><?php esc_html_e( 'Power Badge', 'my-book-showroom' ); ?></h3>
			<table class="form-table">

				<!-- Badge Position -- FREE+ -->
				<tr>
					<th scope="row">
						<?php esc_html_e( 'Power Badge Position', 'my-book-showroom' ); ?>
					</th>
					<td>
						<select name="mbs_setting_appearance_badge_position" id="mbs_setting_appearance_badge_position">
							<?php
							$badge_position = mbs_get_setting( 'appearance', 'badge_position', 'bottom-right' );
							$positions = array(
								'bottom-right'  => __( 'Bottom Right (default)', 'my-book-showroom' ),
								'bottom-left'   => __( 'Bottom Left', 'my-book-showroom' ),
								'bottom-center' => __( 'Bottom Center', 'my-book-showroom' ),
							);
							foreach ( $positions as $val => $label ) :
								printf(
									'<option value="%s"%s>%s</option>',
									esc_attr( $val ),
									selected( $badge_position, $val, false ),
									esc_html( $label )
								);
							endforeach;
							?>
						</select>
						<p class="description">
							<?php esc_html_e( 'Choose where the "Powered by My Book Showroom" badge appears on book and author pages.', 'my-book-showroom' ); ?>
						</p>
					</td>
				</tr>

				<!-- Badge Toggle -- all tiers; FREE locked ON -->
				<tr>
					<th scope="row">
						<?php esc_html_e( 'Show Power Badge', 'my-book-showroom' ); ?>
					</th>
					<td>
						<?php if ( mbs_is_pro() ) : ?>
							<!-- PRO/PUB: opt-out toggle, on by default -->
							<label for="mbs_setting_appearance_badge_enabled">
								<input type="checkbox"
								       name="mbs_setting_appearance_badge_enabled"
								       id="mbs_setting_appearance_badge_enabled"
								       value="1"
								       <?php checked( mbs_get_setting( 'appearance', 'badge_enabled', true ) ); ?>>
								<?php esc_html_e( 'Display the My Book Showroom badge on your site', 'my-book-showroom' ); ?>
							</label>
						<?php else : ?>
							<!-- FREE: locked ON, no opt-out -->
							<label>
								<input type="checkbox" checked disabled aria-disabled="true">
								<?php esc_html_e( 'Display the My Book Showroom badge on your site', 'my-book-showroom' ); ?>
							</label>
						<?php endif; ?>
						<p class="description">
							<?php
							if ( mbs_is_pro() ) :
								esc_html_e( 'Show off your good taste. The badge lets other authors and publishers discover My Book Showroom — and it looks great doing it.', 'my-book-showroom' );
							else :
								esc_html_e( 'The Power Badge is always displayed on the FREE tier. Upgrade to PRO to make it optional.', 'my-book-showroom' );
							endif;
							?>
						</p>
					</td>
				</tr>

			</table>
		</div>
		<?php
	}

}
