<?php
/**
 * Wizard Done step — recap + Bootstrap inline + Master Switch + showcase.
 *
 * @package SkyEmagSync
 */

defined( 'ABSPATH' ) || exit;

$is_premium = SkyEmagSync\Plugin::is_premium();
$creds      = (array) SkyEmagSync\Options::get( SkyEmagSync\Options::API_CREDENTIALS, [] );
$username   = isset( $creds['username'] ) ? (string) $creds['username'] : '—';
$region     = isset( $creds['region'] )   ? strtoupper( (string) $creds['region'] ) : '—';
$margin     = (float) SkyEmagSync\Options::get( SkyEmagSync\Options::GLOBAL_MARGIN, 0 );
$stock_pct  = (int)   SkyEmagSync\Options::get( SkyEmagSync\Options::GLOBAL_STOCK_PCT, 100 );
$schedule   = (string) SkyEmagSync\Options::get( SkyEmagSync\Options::SYNC_SCHEDULE, SkyEmagSync\Options::DEFAULT_SCHEDULE );
$rounding   = (string) SkyEmagSync\Options::get( SkyEmagSync\Options::ROUNDING_RULE, '2decimals' );
$bs_mode    = SkyEmagSync\Options::bootstrap_mode();
?>
<h2>✓ <?php esc_html_e( 'Configuration saved', 'skyservers-product-sync-for-emag' ); ?></h2>

<div class="skyemag-wizard-recap">
	<strong><?php esc_html_e( 'Recap', 'skyservers-product-sync-for-emag' ); ?>:</strong>
	<ul>
		<li>
			<?php
			printf(
				/* translators: %1$s: username, %2$s: region */
				esc_html__( 'Connected to eMAG as: %1$s (%2$s)', 'skyservers-product-sync-for-emag' ),
				esc_html( $username ),
				esc_html( $region )
			);
			?>
		</li>
		<li>
			<?php
			printf(
				/* translators: %1$.2f: margin percent, %2$d: stock percent, %3$s: schedule label, %4$s: rounding rule */
				esc_html__( 'Margin %1$.2f%%, Stock %2$d%%, Schedule %3$s, Rounding %4$s', 'skyservers-product-sync-for-emag' ),
				(float) $margin,
				(int) $stock_pct,
				esc_html( $schedule ),
				esc_html( $rounding )
			);
			?>
		</li>
	</ul>
</div>

<h3><?php esc_html_e( 'Now: import your eMAG data', 'skyservers-product-sync-for-emag' ); ?></h3>
<p style="font-size:13px;"><?php esc_html_e( 'Before turning on automatic sync, run the Bootstrap import. It pulls every active offer from your eMAG account and matches them with your WooCommerce products by SKU. After it finishes, the Products page shows which products are ready to sync (Mapped) and which need attention (Unmapped).', 'skyservers-product-sync-for-emag' ); ?></p>

<?php if ( 'preserve_emag_prices' === $bs_mode ) : ?>
	<p style="font-size:13px;background:#f0f6fc;border-left:4px solid #2271b1;padding:8px 12px;margin-top:0;">
		<strong><?php esc_html_e( 'Smart Bootstrap is ON.', 'skyservers-product-sync-for-emag' ); ?></strong>
		<?php esc_html_e( 'For every matched product, the importer will read your current eMAG sale price and store the implied margin as a per-product override — your existing eMAG prices will stay intact when sync kicks in.', 'skyservers-product-sync-for-emag' ); ?>
	</p>
<?php endif; ?>

<button type="button" class="button button-primary" data-skyemag-bootstrap-run id="skyemag-bootstrap-button">
	▶ <?php esc_html_e( 'Run Bootstrap Import (~60 seconds)', 'skyservers-product-sync-for-emag' ); ?>
</button>

<div id="skyemag-bootstrap-progress" style="display:none;margin-top:10px;">
	<div class="skyemag-progress-bar"><div class="skyemag-progress-bar-fill" id="skyemag-bootstrap-fill"></div></div>
	<p id="skyemag-bootstrap-status" style="font-size:13px;color:#646970;"></p>
</div>

<div id="skyemag-bootstrap-result" style="margin-top:10px;font-size:13px;"></div>

<hr style="margin:24px 0;">

<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
	<?php wp_nonce_field( SkyEmagSync\Admin\SetupWizard::NONCE ); ?>
	<input type="hidden" name="action" value="<?php echo esc_attr( SkyEmagSync\Admin\SetupWizard::POST_FINISH ); ?>">

	<h3><?php esc_html_e( 'Master Switch — automatic sync', 'skyservers-product-sync-for-emag' ); ?></h3>
	<label style="font-weight:normal;">
		<input type="checkbox" name="skyemag_enable_master" value="1">
		<?php esc_html_e( 'Enable automatic sync now', 'skyservers-product-sync-for-emag' ); ?>
	</label>
	<p style="font-size:12px;color:#646970;">
		<?php esc_html_e( "Leave this OFF until you've checked the Products page after the import. You can turn it on from Settings any time.", 'skyservers-product-sync-for-emag' ); ?>
	</p>

	<h3><?php esc_html_e( 'Next steps', 'skyservers-product-sync-for-emag' ); ?></h3>
	<button type="submit" class="button button-primary">
		<?php esc_html_e( 'Go to Products', 'skyservers-product-sync-for-emag' ); ?>
	</button>
	<a href="<?php echo esc_url( admin_url( 'admin.php?page=' . SkyEmagSync\Admin\Menu::HELP_SLUG ) ); ?>" class="button">
		<?php esc_html_e( 'Open Help', 'skyservers-product-sync-for-emag' ); ?>
	</a>
</form>

<?php if ( ! $is_premium ) : ?>
	<hr style="margin:28px 0 18px;">
	<h3 style="text-align:center;">💎 <?php esc_html_e( 'Want more? Pro unlocks', 'skyservers-product-sync-for-emag' ); ?></h3>
	<div style="display:grid;grid-template-columns:repeat(3,1fr);gap:14px;margin:14px 0;">
		<div class="skyemag-showcase-card">
			<h4><?php esc_html_e( 'Publish products', 'skyservers-product-sync-for-emag' ); ?></h4>
			<p style="font-size:12px;color:#2c3338;"><?php esc_html_e( 'Send WC products to eMAG with category mapping and characteristics.', 'skyservers-product-sync-for-emag' ); ?></p>
		</div>
		<div class="skyemag-showcase-card">
			<h4><?php esc_html_e( 'Import orders', 'skyservers-product-sync-for-emag' ); ?></h4>
			<p style="font-size:12px;color:#2c3338;"><?php esc_html_e( 'Orders flow into WC automatically via webhook + manual import.', 'skyservers-product-sync-for-emag' ); ?></p>
		</div>
		<div class="skyemag-showcase-card">
			<h4><?php esc_html_e( 'AWB shipping', 'skyservers-product-sync-for-emag' ); ?></h4>
			<p style="font-size:12px;color:#2c3338;"><?php esc_html_e( 'Issue and print shipping labels without leaving WordPress.', 'skyservers-product-sync-for-emag' ); ?></p>
		</div>
	</div>
	<p style="text-align:center;">
		<a href="<?php echo esc_url( SkyEmagSync\Admin\Menu::upgrade_url() ); ?>" class="button button-primary" target="_blank" rel="noopener">
			<?php esc_html_e( 'See all Pro features → Upgrade', 'skyservers-product-sync-for-emag' ); ?>
		</a>
	</p>
<?php endif; ?>
