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

if (!empty($grouped_fields)) :
    $iwbvel_compatibles = [];
    if (!empty($grouped_fields['compatibles'])) {
        $iwbvel_compatibles = $grouped_fields['compatibles'];
        unset($grouped_fields['compatibles']);
    }
?>
    <div class="iwbvel-column-profile-fields">
        <?php foreach ($grouped_fields as $iwbvel_group_name => $iwbvel_column_fields) : ?>
            <?php if (!empty($iwbvel_column_fields)) : ?>
                <div class="iwbvel-column-profile-fields-group">
                    <div class="group-title">
                        <h3><?php echo esc_html($iwbvel_group_name); ?></h3>
                    </div>
                    <ul>
                        <?php foreach ($iwbvel_column_fields as $iwbvel_name => $iwbvel_column_field) : ?>
                            <li>
                                <label>
                                    <input type="checkbox" name="columns[]" value="<?php echo esc_attr($iwbvel_name); ?>">
                                    <?php echo esc_html($iwbvel_column_field['label']); ?>
                                </label>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                </div>
            <?php endif; ?>
        <?php
        endforeach;
        if (!empty($iwbvel_compatibles) && is_array($iwbvel_compatibles)) : ?>
            <div class="iwbvel-column-profile-compatibles-group">
                <strong class="iwbvel-column-profile-compatibles-group-title"><?php esc_html_e('Fields from third-party plugins', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?></strong>
                <?php foreach ($iwbvel_compatibles as $iwbvel_compatible_name => $iwbvel_compatible_fields) : ?>
                    <div class="iwbvel-column-profile-fields-group">
                        <div class="group-title">
                            <h3><?php echo esc_html($iwbvel_compatible_name); ?></h3>
                        </div>
                        <ul>
                            <?php foreach ($iwbvel_compatible_fields as $iwbvel_compatible_field_name => $iwbvel_compatible_field) : ?>
                                <li>
                                    <label>
                                        <input type="checkbox" name="columns[]" value="<?php echo esc_attr($iwbvel_compatible_field_name); ?>">
                                        <?php echo esc_html($iwbvel_compatible_field['label']); ?>
                                    </label>
                                </li>
                            <?php endforeach; ?>
                        </ul>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </div>
<?php endif; ?>