<?php

/**
 * Quantity Settings.
 *
 * Shows quantity settings with PRO badge for free users.
 *
 * @since   4.4.0
 * @package Extra Product Options for WooCommerce
 *
 * Available Variables (from element-form.php):
 * @var array  $epofw_field_data        The field/element data array.
 * @var string $epofw_field_type        The field type (text, select, etc.).
 * @var array  $epofw_options_data      The field settings array.
 * @var string $epofw_field_name_prefix The form field name prefix.
 * @var string $epofw_field_id          The field ID/key.
 */
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
// Get premium field data for disabled state.
$epofw_prem_data = epofw_get_premium_field_data();
// Get quantity settings values.
$enable_af_per_qty = epofw_check_array_key_exists( 'enable_af_per_qty', $epofw_options_data );
$epofw_af_product_quantity = epofw_check_array_key_exists( 'epofw_af_product_quantity', $epofw_options_data );
$field_default_quantity = epofw_check_array_key_exists( 'epofw_af_default_quantity', $epofw_options_data );
$field_min_quantity = epofw_check_array_key_exists( 'epofw_af_min_quantity', $epofw_options_data );
$field_max_quantity = epofw_check_array_key_exists( 'epofw_af_max_quantity', $epofw_options_data );
?>

<div class="epofw-tab-content" data-tab="quantity-settings">
	<div class="epofw-onboarding-hint">
		<div class="epofw-onboarding-hint-content">
			<span class="epofw-onboarding-icon"><i class="dashicons dashicons-info-outline"></i></span>
			<span class="epofw-onboarding-text"><?php 
esc_html_e( 'Enable quantity selection for addon fields, allowing customers to specify how many of each option they want. Perfect for personalization services or bulk addons.', 'extra-product-options-for-woocommerce' );
?></span>
		</div>
		<?php 
epofw_render_tutorial_buttons( 'quantity_options', 'small', true );
?>
	</div>
	<div class="epofw-form-group<?php 
echo esc_attr( $epofw_prem_data['class'] );
?>">
		<div class="epofw-field-label">
			<label for="enable_af_per_qty"><?php 
esc_html_e( 'Enable Quantity', 'extra-product-options-for-woocommerce' );
echo wp_kses( $epofw_prem_data['badge'], epofw_get_badge_allowed_html() );
?></label>
			<div class="epofw-field-description">
				<?php 
esc_html_e( 'Enable quantity for this field.', 'extra-product-options-for-woocommerce' );
?>
			</div>
		</div>
		<div class="epofw-field-input">
			<input type="checkbox" 
			<?php 
?>
			id="enable_af_per_qty" value="on" <?php 
checked( $enable_af_per_qty, 'on' );
?> class="epofw-has-sub" data-nextfe="enable_af_qty_option" data-crntfe="enable_af_per_qty"<?php 
echo esc_attr( $epofw_prem_data['disabled'] );
?>>
			<label for="enable_af_per_qty" class="toggle-switch"></label>
		</div>
	</div>

	<div class="epofw-quantity-fields-container" id="enable_af_qty_option" style="display: <?php 
echo ( 'on' === $enable_af_per_qty ? 'block' : 'none' );
?>;">
		<div class="epofw-form-group<?php 
echo esc_attr( $epofw_prem_data['class'] );
?>">
			<div class="epofw-field-label">
				<label for="epofw_af_product_quantity"><?php 
esc_html_e( 'Product Quantity', 'extra-product-options-for-woocommerce' );
echo wp_kses( $epofw_prem_data['badge'], epofw_get_badge_allowed_html() );
?></label>
				<div class="epofw-field-description">
					<?php 
esc_html_e( 'If you count addons quantity same as product qty then check above checkbox.', 'extra-product-options-for-woocommerce' );
?>
				</div>
			</div>
			<div class="epofw-field-input">
				<input type="checkbox" 
				<?php 
?>
				id="epofw_af_product_quantity" value="on" <?php 
checked( $epofw_af_product_quantity, 'on' );
?> class="epofw_af_current_field_show_hide"<?php 
echo esc_attr( $epofw_prem_data['disabled'] );
?>>
				<label for="epofw_af_product_quantity" class="toggle-switch"></label>
			</div>
		</div>

		<div class="epofw-form-group<?php 
echo esc_attr( $epofw_prem_data['class'] );
?> hide_on_epofw_af_product_quantity<?php 
echo ( 'on' === $epofw_af_product_quantity ? ' epofw-hide' : '' );
?>">
			<div class="epofw-field-label">
				<label for="field_default_quantity"><?php 
esc_html_e( 'Default Quantity', 'extra-product-options-for-woocommerce' );
echo wp_kses( $epofw_prem_data['badge'], epofw_get_badge_allowed_html() );
?></label>
				<div class="epofw-field-description">
					<?php 
esc_html_e( 'Set the default quantity value that will be pre-filled when the field loads.', 'extra-product-options-for-woocommerce' );
?>
				</div>
			</div>
			<div class="epofw-field-input">
				<input type="number" 
				<?php 
?>
				id="field_default_quantity" value="<?php 
echo esc_attr( $field_default_quantity );
?>" class="epofw-form-control" min="0"<?php 
echo esc_attr( $epofw_prem_data['disabled'] );
?>>
			</div>
		</div>

		<div class="epofw-form-group<?php 
echo esc_attr( $epofw_prem_data['class'] );
?> hide_on_epofw_af_product_quantity<?php 
echo ( 'on' === $epofw_af_product_quantity ? ' epofw-hide' : '' );
?>">
			<div class="epofw-field-label">
				<label for="field_min_quantity"><?php 
esc_html_e( 'Minimum Quantity', 'extra-product-options-for-woocommerce' );
echo wp_kses( $epofw_prem_data['badge'], epofw_get_badge_allowed_html() );
?></label>
				<div class="epofw-field-description">
					<?php 
esc_html_e( 'Set the minimum quantity that users can select for this field.', 'extra-product-options-for-woocommerce' );
?>
				</div>
			</div>
			<div class="epofw-field-input">
				<input type="number" 
				<?php 
?>
				id="field_min_quantity" value="<?php 
echo esc_attr( $field_min_quantity );
?>" class="epofw-form-control" min="0"<?php 
echo esc_attr( $epofw_prem_data['disabled'] );
?>>
			</div>
		</div>

		<div class="epofw-form-group<?php 
echo esc_attr( $epofw_prem_data['class'] );
?> hide_on_epofw_af_product_quantity<?php 
echo ( 'on' === $epofw_af_product_quantity ? ' epofw-hide' : '' );
?>">
			<div class="epofw-field-label">
				<label for="field_max_quantity"><?php 
esc_html_e( 'Maximum Quantity', 'extra-product-options-for-woocommerce' );
echo wp_kses( $epofw_prem_data['badge'], epofw_get_badge_allowed_html() );
?></label>
				<div class="epofw-field-description">
					<?php 
esc_html_e( 'Set the maximum quantity that users can select for this field.', 'extra-product-options-for-woocommerce' );
?>
				</div>
			</div>
			<div class="epofw-field-input">
				<input type="number" 
				<?php 
?>
				id="field_max_quantity" value="<?php 
echo esc_attr( $field_max_quantity );
?>" class="epofw-form-control" min="0"<?php 
echo esc_attr( $epofw_prem_data['disabled'] );
?>>
			</div>
		</div>
	</div>
</div>
