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

	/**
	 * Render the Bestseller Badge settings section. Internalizes PRO check (RF-009).
	 *
	 * @return void
	 */
	/**
	 * Render the DISPLAY-2 Bestseller Badge rank threshold setting.
	 *
	 * @param bool $is_pro Whether the current license is PRO or higher.
	 * @return void
	 */
	public static function render(): void {
		$is_pro = mbs_is_pro();
		$threshold = (int) get_option( 'mbs_setting_bestseller_rank_threshold', 100 );
		?>
		<div class="mbs-badge-settings-wrap" style="margin-top:1rem;">
			<h3 style="margin-bottom:0.5rem;"><?php esc_html_e( 'Bestseller Badge', 'my-book-showroom' ); ?></h3>
			<?php if ( ! $is_pro ) : ?>
			<p class="description">
				<?php esc_html_e( 'The Bestseller Badge requires a PRO license.', 'my-book-showroom' ); ?>
			</p>
			<?php else : ?>
			<table class="form-table" role="presentation">
				<tr>
					<th scope="row">
						<?php mbs_settings_th(
							'mbs_bestseller_rank_threshold',
							__( 'Bestseller Badge Threshold (sales rank)', 'my-book-showroom' ),
							__( 'The Bestseller badge appears on book pages and book cards when a book\'s best Amazon sales rank is at or below this number. Requires Amazon PA-API credentials under Settings → Import/Export → Amazon PA-API, and at least one ASIN on each book.', 'my-book-showroom' )
						); ?>
					</th>
					<td>
						<input type="number"
						       id="mbs_bestseller_rank_threshold"
						       name="mbs_setting_bestseller_rank_threshold"
						       value="<?php echo esc_attr( $threshold ); ?>"
						       min="1" max="1000000" class="small-text">
						<p class="description">
							<?php esc_html_e( 'Books with a sales rank at or below this number will display the Bestseller badge.', 'my-book-showroom' ); ?>
						</p>
					</td>
				</tr>
			</table>
			<?php endif; ?>
		</div>
		<?php
	}

}
