<?php

/**
 * Row Form.
 *
 * @since   4.4.0
 * @package Extra Product Options for WooCommerce
 *
 * Available Variables (from addon-builder.php):
 * $epofw_section_id - The section ID.
 * $epofw_group_id - The row group ID.
 * $epofw_row_group_settings - The row group settings array.
 */
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
// Ensure required variables are set with defaults.
$epofw_section_id = ( isset( $epofw_section_id ) ? $epofw_section_id : '' );
$epofw_group_id = ( isset( $epofw_group_id ) ? $epofw_group_id : '' );
$epofw_row_group_settings = ( isset( $epofw_row_group_settings ) ? $epofw_row_group_settings : array() );
// OPTIMIZED: Create flat name prefix for row group (v4.4.0).
// Row group data is sent flat, then organized into hierarchical structure during save.
$epofw_row_name_prefix = "epofw_row_group[{$epofw_group_id}]";
// Store associations as hidden fields.
echo '<input type="hidden" name="' . esc_attr( $epofw_row_name_prefix ) . '[section_id]" value="' . esc_attr( $epofw_section_id ) . '">';
echo '<input type="hidden" name="' . esc_attr( $epofw_row_name_prefix ) . '[group_id]" value="' . esc_attr( $epofw_group_id ) . '">';
// Row Group Settings (Layout-only: gap and alignment).
$epofw_row_group_gap = epofw_check_array_key_exists( 'gap', $epofw_row_group_settings );
// Default gap value if not set.
if ( empty( $epofw_row_group_gap ) ) {
    $epofw_row_group_gap = '16';
}
// Premium check for row settings.
$epofw_is_premium_user = false;
$epofw_row_premium_class = ( !$epofw_is_premium_user ? ' epofw-premium-field-disabled' : '' );
$epofw_row_premium_badge = ( !$epofw_is_premium_user ? '<span class="epofw-pro-badge-inline">' . esc_html__( 'PRO', 'extra-product-options-for-woocommerce' ) . '</span>' : '' );
$epofw_row_premium_disabled = ( !$epofw_is_premium_user ? ' disabled' : '' );
// Layout settings.
$epofw_row_group_alignment = epofw_check_array_key_exists( 'alignment', $epofw_row_group_settings );
?>

<div class="epofw-form-group">
	<div class="epofw-field-label">
		<label for="row_group_gap_<?php 
echo esc_attr( $epofw_group_id );
?>"><?php 
esc_html_e( 'Gap Between Columns', 'extra-product-options-for-woocommerce' );
?></label>
		<div class="epofw-field-description">
			<?php 
esc_html_e( 'Set the spacing between columns within this row. This controls the gap between fields when displayed side-by-side. Default: 16px. Leave empty to use default. Its consider as the px units.', 'extra-product-options-for-woocommerce' );
?>
		</div>
	</div>
	<div class="epofw-field-input">
		<input type="number" name="<?php 
echo esc_attr( $epofw_row_name_prefix );
?>[gap]" id="row_group_gap_<?php 
echo esc_attr( $epofw_group_id );
?>" value="<?php 
echo esc_attr( $epofw_row_group_gap );
?>" placeholder="16" min="0" step="1">
	</div>
</div>

<div class="epofw-form-group<?php 
echo esc_attr( $epofw_row_premium_class );
?>">
	<div class="epofw-field-label">
		<label for="row_group_alignment_<?php 
echo esc_attr( $epofw_group_id );
?>"><?php 
esc_html_e( 'Alignment', 'extra-product-options-for-woocommerce' );
echo wp_kses( $epofw_row_premium_badge, epofw_get_badge_allowed_html() );
?></label>
		<div class="epofw-field-description">
			<?php 
esc_html_e( 'Choose how columns align within the row group (layout property).', 'extra-product-options-for-woocommerce' );
?>
		</div>
	</div>
	<div class="epofw-field-input">
		<select 
		<?php 
?>
		id="row_group_alignment_<?php 
echo esc_attr( $epofw_group_id );
?>" class="epofw-form-control"<?php 
echo esc_attr( $epofw_row_premium_disabled );
?>>
			<option value=""><?php 
esc_html_e( 'Select Alignment', 'extra-product-options-for-woocommerce' );
?></option>
			<option value="start" <?php 
selected( $epofw_row_group_alignment, 'start' );
?>><?php 
esc_html_e( 'Start', 'extra-product-options-for-woocommerce' );
?></option>
			<option value="center" <?php 
selected( $epofw_row_group_alignment, 'center' );
?>><?php 
esc_html_e( 'Center', 'extra-product-options-for-woocommerce' );
?></option>
			<option value="end" <?php 
selected( $epofw_row_group_alignment, 'end' );
?>><?php 
esc_html_e( 'End', 'extra-product-options-for-woocommerce' );
?></option>
			<option value="stretch" <?php 
selected( $epofw_row_group_alignment, 'stretch' );
?>><?php 
esc_html_e( 'Stretch', 'extra-product-options-for-woocommerce' );
?></option>
		</select>
	</div>
</div>
