<?php
/**
 * Wizard Step 3 — Pricing & Stock defaults.
 *
 * @package SkyEmagSync
 */

defined( 'ABSPATH' ) || exit;

$is_premium  = SkyEmagSync\Plugin::is_premium();
$margin      = (float) SkyEmagSync\Options::get( SkyEmagSync\Options::GLOBAL_MARGIN, 0 );
$min_margin  = SkyEmagSync\Options::get( SkyEmagSync\Options::GLOBAL_MIN_MARGIN, '' );
$max_margin  = SkyEmagSync\Options::get( SkyEmagSync\Options::GLOBAL_MAX_MARGIN, '' );
$stock_pct   = (int) SkyEmagSync\Options::get( SkyEmagSync\Options::GLOBAL_STOCK_PCT, 100 );
$min_wc      = (int) SkyEmagSync\Options::get( SkyEmagSync\Options::MIN_WC_STOCK, 0 );
$rounding    = (string) SkyEmagSync\Options::get( SkyEmagSync\Options::ROUNDING_RULE, '2decimals' );
$use_regular = (bool) SkyEmagSync\Options::get( SkyEmagSync\Options::USE_REGULAR_PRICE, false );
$bs_mode     = SkyEmagSync\Options::bootstrap_mode();
?>
<h2><?php esc_html_e( 'Pricing & Stock defaults', 'skyservers-product-sync-for-emag' ); ?></h2>
<p><?php esc_html_e( 'These set the baseline for every synced product. You can override them per product on the Products page.', 'skyservers-product-sync-for-emag' ); ?></p>

<?php SkyEmagSync\Admin\SetupWizard::open_step_form( 3 ); ?>

	<label for="skyemag-margin"><?php esc_html_e( 'Global Margin %', 'skyservers-product-sync-for-emag' ); ?></label>
	<input id="skyemag-margin" type="number" step="0.01" name="skyemag_margin" value="<?php echo esc_attr( (string) $margin ); ?>">
	<p style="font-size:12px;color:#646970;"><code>eMAG sale_price = WC price × (1 + margin/100)</code></p>

	<label style="margin-top:14px;"><?php esc_html_e( 'Initial import strategy', 'skyservers-product-sync-for-emag' ); ?></label>
	<label style="font-weight:normal;display:block;margin:6px 0;">
		<input type="radio" name="skyemag_bootstrap_mode" value="global_margin" <?php checked( $bs_mode, 'global_margin' ); ?>>
		<?php esc_html_e( 'Apply the global margin to all matched products', 'skyservers-product-sync-for-emag' ); ?>
		<span style="display:block;font-size:12px;color:#646970;margin-left:24px;">
			<?php esc_html_e( 'First sync overwrites existing eMAG prices with WC price × (1 + margin/100). Choose this if you have not been selling on eMAG yet, or if your eMAG catalogue is empty.', 'skyservers-product-sync-for-emag' ); ?>
		</span>
	</label>
	<label style="font-weight:normal;display:block;margin:6px 0 14px;">
		<input type="radio" name="skyemag_bootstrap_mode" value="preserve_emag_prices" <?php checked( $bs_mode, 'preserve_emag_prices' ); ?>>
		<?php esc_html_e( 'Preserve existing eMAG prices — capture per-product margins from your current offers', 'skyservers-product-sync-for-emag' ); ?>
		<span style="display:block;font-size:12px;color:#646970;margin-left:24px;">
			<?php esc_html_e( 'Recommended if you already have a catalogue on eMAG. Bootstrap reads each existing offer price, derives the implied margin against your WooCommerce price, and stores it as a per-product override. Your eMAG prices stay unchanged until you adjust margins manually.', 'skyservers-product-sync-for-emag' ); ?>
		</span>
	</label>

	<label for="skyemag-min-margin"><?php esc_html_e( 'Global Min Margin %', 'skyservers-product-sync-for-emag' ); ?></label>
	<input id="skyemag-min-margin" type="number" step="0.01" name="skyemag_min_margin" value="<?php echo esc_attr( (string) $min_margin ); ?>" placeholder="<?php esc_attr_e( 'optional', 'skyservers-product-sync-for-emag' ); ?>">

	<label for="skyemag-max-margin"><?php esc_html_e( 'Global Max Margin %', 'skyservers-product-sync-for-emag' ); ?></label>
	<input id="skyemag-max-margin" type="number" step="0.01" name="skyemag_max_margin" value="<?php echo esc_attr( (string) $max_margin ); ?>" placeholder="<?php esc_attr_e( 'optional', 'skyservers-product-sync-for-emag' ); ?>">

	<label for="skyemag-stock-pct"><?php esc_html_e( 'Global Stock %', 'skyservers-product-sync-for-emag' ); ?></label>
	<input id="skyemag-stock-pct" type="number" min="0" max="100" name="skyemag_stock_pct" value="<?php echo esc_attr( (string) $stock_pct ); ?>">

	<label for="skyemag-min-wc-stock">
		<?php esc_html_e( 'Minimum WC Stock', 'skyservers-product-sync-for-emag' ); ?>
	</label>
	<input id="skyemag-min-wc-stock" type="number" min="0"
		name="skyemag_min_wc_stock"
		value="<?php echo esc_attr( (string) $min_wc ); ?>"
		title="<?php esc_attr_e( "Reserve safety stock that won't be sent to eMAG. When WooCommerce stock is at or below this value, the offer is sent to eMAG with stock 0.", 'skyservers-product-sync-for-emag' ); ?>">

	<label><?php esc_html_e( 'Price Rounding', 'skyservers-product-sync-for-emag' ); ?></label>
	<label style="font-weight:normal;"><input type="radio" name="skyemag_rounding" value="none"      <?php checked( $rounding, 'none' ); ?>> <?php esc_html_e( 'None', 'skyservers-product-sync-for-emag' ); ?></label>
	<label style="font-weight:normal;"><input type="radio" name="skyemag_rounding" value="2decimals" <?php checked( $rounding, '2decimals' ); ?>> <?php esc_html_e( '2 decimals', 'skyservers-product-sync-for-emag' ); ?></label>
	<label style="font-weight:normal;"><input type="radio" name="skyemag_rounding" value="end99"     <?php checked( $rounding, 'end99' ); ?>> <?php esc_html_e( 'End in .99', 'skyservers-product-sync-for-emag' ); ?></label>

	<label><?php esc_html_e( 'Price source', 'skyservers-product-sync-for-emag' ); ?></label>
	<label style="font-weight:normal;"><input type="radio" name="skyemag_use_regular_price" value="0" <?php checked( ! $use_regular ); ?>> <?php esc_html_e( 'WC sale price', 'skyservers-product-sync-for-emag' ); ?></label>
	<label style="font-weight:normal;"><input type="radio" name="skyemag_use_regular_price" value="1" <?php checked( $use_regular ); ?>> <?php esc_html_e( 'WC regular price', 'skyservers-product-sync-for-emag' ); ?></label>

	<?php SkyEmagSync\Admin\SetupWizard::render_step_buttons( 3 ); ?>
</form>

<?php if ( ! $is_premium ) : ?>
	<?php
	$features = SkyEmagSync\Admin\SetupWizard::pro_features_for_step( 3 );
	$card_title = __( '💎 Pro extras you might like', 'skyservers-product-sync-for-emag' );
	include SKYEMAG_PLUGIN_DIR . 'includes/Admin/templates/wizard-showcase-card.php';
	?>
<?php endif; ?>

<p style="font-size:12px;color:#646970;">
	<?php esc_html_e( 'Tip: set Min % low (5-10%) so price moves stay inside bounds without manual adjustment.', 'skyservers-product-sync-for-emag' ); ?>
</p>
