<?php
/**
 * Wizard Step 4 — Sync schedule & filters.
 *
 * @package SkyEmagSync
 */

defined( 'ABSPATH' ) || exit;

$is_premium  = SkyEmagSync\Plugin::is_premium();
$schedule    = (string) SkyEmagSync\Options::get( SkyEmagSync\Options::SYNC_SCHEDULE, SkyEmagSync\Options::DEFAULT_SCHEDULE );
$min_price   = (float)  SkyEmagSync\Options::get( SkyEmagSync\Options::SYNC_MIN_PRICE_EX_VAT, 0 );
$max_weight  = (float)  SkyEmagSync\Options::get( SkyEmagSync\Options::SYNC_MAX_WEIGHT_KG, 0 );
$skip_sku    = (string) SkyEmagSync\Options::get( SkyEmagSync\Options::SYNC_SKIP_SKU_PATTERN, '' );
$skip_zero   = (bool)   SkyEmagSync\Options::get( SkyEmagSync\Options::SYNC_SKIP_ZERO_STOCK, false );

$schedules_all = [
	'15min' => __( 'Every 15 minutes', 'skyservers-product-sync-for-emag' ),
	'30min' => __( 'Every 30 minutes', 'skyservers-product-sync-for-emag' ),
	'1h'    => __( 'Every hour', 'skyservers-product-sync-for-emag' ),
	'3h'    => __( 'Every 3 hours', 'skyservers-product-sync-for-emag' ),
	'6h'    => __( 'Every 6 hours', 'skyservers-product-sync-for-emag' ),
	'12h'   => __( 'Every 12 hours', 'skyservers-product-sync-for-emag' ),
	'daily' => __( 'Daily', 'skyservers-product-sync-for-emag' ),
];
?>
<h2><?php esc_html_e( 'Sync schedule & filters', 'skyservers-product-sync-for-emag' ); ?></h2>

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

	<label for="skyemag-schedule"><?php esc_html_e( 'Sync frequency', 'skyservers-product-sync-for-emag' ); ?></label>
	<select id="skyemag-schedule" name="skyemag_schedule">
		<?php foreach ( $schedules_all as $key => $label ) : ?>
			<option value="<?php echo esc_attr( $key ); ?>" <?php selected( $schedule, $key ); ?>>
				<?php echo esc_html( $label ); ?>
			</option>
		<?php endforeach; ?>
	</select>

	<h3><?php esc_html_e( 'Sync filters (optional)', 'skyservers-product-sync-for-emag' ); ?></h3>

	<label for="skyemag-min-price"><?php esc_html_e( 'Skip products with price below (ex VAT)', 'skyservers-product-sync-for-emag' ); ?></label>
	<input id="skyemag-min-price" type="number" step="0.01" min="0" name="skyemag_min_price" value="<?php echo esc_attr( (string) $min_price ); ?>" placeholder="0">

	<label for="skyemag-max-weight"><?php esc_html_e( 'Skip products with weight above (kg)', 'skyservers-product-sync-for-emag' ); ?></label>
	<input id="skyemag-max-weight" type="number" step="0.01" min="0" name="skyemag_max_weight" value="<?php echo esc_attr( (string) $max_weight ); ?>" placeholder="0">

	<label for="skyemag-skip-sku"><?php esc_html_e( 'Skip products matching SKU regex', 'skyservers-product-sync-for-emag' ); ?></label>
	<input id="skyemag-skip-sku" type="text" name="skyemag_skip_sku_pattern" value="<?php echo esc_attr( $skip_sku ); ?>" placeholder="/^DEMO-/i">

	<label style="font-weight:normal;margin-top:12px;">
		<input type="checkbox" name="skyemag_skip_zero_stock" value="1" <?php checked( $skip_zero ); ?>>
		<?php esc_html_e( 'Skip products with zero WC stock', 'skyservers-product-sync-for-emag' ); ?>
	</label>

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

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