<?php
if (!defined('ABSPATH')) exit; // Exit if accessed directly 

$iwbvel_items = $new_form_items['stock'];

foreach ($iwbvel_items as $iwbvel_name => $iwbvel_item):
    $iwbvel_field_id = 'iwbvel-bulk-new-form-' . esc_attr($iwbvel_item['name']);
    $iwbvel_field_type = isset($iwbvel_item['field_type']) ? $iwbvel_item['field_type'] : 'text';

    // Handle section headers
    if ($iwbvel_field_type === 'section_header') {
        echo '<div><strong>' . esc_html($iwbvel_item['label']) . '</strong><hr><div class="iwbvel-mb20"></div></div>';
        continue;
    }
?>
    <div class="iwbvel-form-group" data-name="<?php echo esc_attr($iwbvel_name); ?>" data-type="<?php echo esc_attr($iwbvel_item['update_type']); ?>">
        <div>
            <label for="<?php echo esc_attr($iwbvel_field_id); ?>"><?php echo esc_html($iwbvel_item['label']); ?></label>

            <?php if ($iwbvel_field_type === 'select'): ?>
                <select <?php echo (isset($iwbvel_item['disabled']) && $iwbvel_item['disabled']) ? 'disabled="disabled"' : ''; ?> class="iwbvel-input-md" id="<?php echo esc_attr($iwbvel_field_id); ?>" data-field="value">
                    <?php if (isset($iwbvel_item['first_option'])): ?>
                        <option value=""><?php echo esc_html($iwbvel_item['first_option']); ?></option>
                    <?php endif; ?>
                    <?php if (!empty($iwbvel_item['options'])): ?>
                        <?php foreach ($iwbvel_item['options'] as $iwbvel_key => $iwbvel_value): ?>
                            <option value="<?php echo esc_attr($iwbvel_key); ?>"><?php echo esc_html($iwbvel_value); ?></option>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </select>
            <?php else: ?>
                <?php
                $iwbvel_field_type_path = IWBVEL_VIEWS_DIR . 'bulk_new_products_form/fields_type/' . $iwbvel_field_type . '.php';
                if (file_exists($iwbvel_field_type_path)) {
                    include $iwbvel_field_type_path;
                } else {
                    include IWBVEL_VIEWS_DIR . 'bulk_new_products_form/fields_type/text.php';
                }
                ?>
            <?php endif; ?>
        </div>

        <?php if (isset($iwbvel_item['disabled']) && $iwbvel_item['disabled']): ?>
            <span class="iwbvel-alert-pro-description"><?php esc_html_e('Upgrade to pro version!', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?></span>
        <?php endif; ?>
    </div>
<?php endforeach; ?>