<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Variables in scope (injected via mbs_get_template_part from imp-exp-ui.php).
 * @var bool   $is_registered
 * @var bool   $is_pro
 * @var string $nonce
 * @var string $template_url
 */
?>

		<!-- Panel: Amazon Import (PRO) -->
		<div id="mbs-panel-amazon"
		     class="mbs-imp-exp-panel"
		     role="tabpanel"
		     hidden>
			<h3><?php esc_html_e( 'Amazon Import', 'my-book-showroom' ); ?></h3>

			<?php if ( $is_pro ) : ?>

				<!-- PA-API Credentials (Story 9-1) -->
				<div class="mbs-amazon-credentials">
					<h4><?php esc_html_e( 'PA-API Credentials', 'my-book-showroom' ); ?></h4>
					<table class="form-table mbs-credentials-table"><tbody>
						<tr>
							<th scope="row">
								<label for="mbs-amazon-access-key"><?php esc_html_e( 'Access Key ID', 'my-book-showroom' ); ?></label>
							</th>
							<td>
								<input type="password"
								       id="mbs-amazon-access-key"
								       class="regular-text"
								       placeholder="<?php echo get_option( 'mbs_setting_import_amazon_api_key_encrypted' ) ? esc_attr__( 'Already set — leave blank to keep', 'my-book-showroom' ) : ''; ?>"
								       autocomplete="off" />
							</td>
						</tr>
						<tr>
							<th scope="row">
								<label for="mbs-amazon-secret-key"><?php esc_html_e( 'Secret Access Key', 'my-book-showroom' ); ?></label>
							</th>
							<td>
								<input type="password"
								       id="mbs-amazon-secret-key"
								       class="regular-text"
								       placeholder="<?php echo get_option( 'mbs_setting_import_amazon_api_secret_encrypted' ) ? esc_attr__( 'Already set — leave blank to keep', 'my-book-showroom' ) : ''; ?>"
								       autocomplete="off" />
							</td>
						</tr>
						<tr>
							<th scope="row">
								<label for="mbs-amazon-partner-tag"><?php esc_html_e( 'Associate Tag', 'my-book-showroom' ); ?></label>
							</th>
							<td>
								<input type="text"
								       id="mbs-amazon-partner-tag"
								       class="regular-text"
								       value="<?php echo esc_attr( get_option( 'mbs_setting_amazon_partner_tag', '' ) ); ?>"
								       placeholder="yourtag-20" />
								<p class="description"><?php esc_html_e( 'Your Associates tracking tag, e.g. yourtag-20', 'my-book-showroom' ); ?></p>
							</td>
						</tr>
					</tbody></table>
					<button type="button"
					        id="mbs-amazon-save-credentials-btn"
					        class="button button-secondary"
					        data-nonce="<?php echo esc_attr( $nonce ); ?>">
						<?php esc_html_e( 'Save Credentials', 'my-book-showroom' ); ?>
					</button>
					<span id="mbs-amazon-credentials-message" style="display:none; margin-left:8px;"></span>
				</div><!-- .mbs-amazon-credentials -->

				<p class="mbs-panel-lead"><?php esc_html_e( 'Paste ASINs or ISBNs, one per line. Data is fetched via the Amazon Product Advertising API using the credentials above.', 'my-book-showroom' ); ?></p>

				<input type="hidden" id="mbs-amazon-panel-nonce" value="<?php echo esc_attr( $nonce ); ?>" />

				<label for="mbs-amazon-list" class="screen-reader-text"><?php esc_html_e( 'ASINs or ISBNs, one per line', 'my-book-showroom' ); ?></label>
				<textarea id="mbs-amazon-list"
				          class="mbs-imp-exp-isbn-list"
				          placeholder="B09KGDXQ32&#10;B07VDMB9NZ"
				          spellcheck="false"></textarea>

				<p style="margin-top:12px;">
					<button type="button"
					        id="mbs-amazon-fetch-btn"
					        class="button button-primary">
						<?php esc_html_e( 'Look Up ASINs / ISBNs', 'my-book-showroom' ); ?>
					</button>
				</p>

				<div id="mbs-amazon-message" style="display:none; margin-top:12px;"></div>

				<!-- Progress bar (shown during confirm-import step) -->
				<div id="mbs-amazon-progress-bar" style="display:none;margin-top:1rem;margin-bottom:0.4rem;">
					<div style="background:#e9ecef;border-radius:4px;height:8px;overflow:hidden;">
						<div id="mbs-amazon-bar" style="height:100%;background:#2271b1;width:0%;border-radius:4px;transition:width 0.45s ease;"></div>
					</div>
				</div>
				<div id="mbs-amazon-msgarea" style="display:none;margin:0 0 0.5rem;font-size:0.875rem;color:#555;"></div>
				<p id="mbs-amazon-status" style="display:none;margin:0.5rem 0;font-size:0.875rem;"></p>

				<div id="mbs-amazon-candidates-preview"></div>

			<?php else : ?>
				<?php MBS_Pro_Gate::comment( 'Amazon Import' ); ?>
				<div class="mbs-imp-exp-soon">
					<span class="dashicons dashicons-lock"></span>
					<p><?php esc_html_e( 'Amazon import requires a PRO license.', 'my-book-showroom' ); ?></p>
				</div>
			<?php endif; ?>
		</div><!-- #mbs-panel-amazon -->
