<?php

use iwbvel\classes\helpers\Sanitizer;

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

$iwbvel_items = $edit_form_items['taxonomies'];

foreach ($iwbvel_items as $iwbvel_group_name => $iwbvel_group_item):
    $iwbvel_field_id = 'iwbvel-bulk-edit-form-' . esc_attr($iwbvel_group_name);
?>
    <div class="iwbvel-form-group">
        <div>
            <strong><?php echo esc_html($iwbvel_group_item['label']); ?></strong>
            <hr>
            <div class="iwbvel-mb20"></div>
        </div>
    </div>

    <?php if (!empty($taxonomies[$iwbvel_group_name])): ?>
        <?php foreach ($taxonomies[$iwbvel_group_name] as $iwbvel_name => $iwbvel_taxonomy):
            if (in_array($iwbvel_name, ['pos_product_visibility'])) {
                continue;
            }

            $iwbvel_tax_field_id = $iwbvel_field_id . '-' . esc_attr($iwbvel_name);
            $iwbvel_tax_disabled = isset($iwbvel_group_item['disabled']) && $iwbvel_group_item['disabled'] && ($iwbvel_group_name === 'attribute' || $iwbvel_taxonomy['label'] === 'Brands');
        ?>
            <div class="iwbvel-form-group" data-name="<?php echo esc_attr($iwbvel_name); ?>" data-type="<?php echo esc_attr($iwbvel_group_item['update_type']); ?>">
                <div>
                    <label for="<?php echo esc_attr($iwbvel_tax_field_id); ?>"><?php echo esc_html($iwbvel_taxonomy['label']); ?></label>

                    <select <?php echo ($iwbvel_tax_disabled) ? 'disabled="disabled"' : ''; ?>
                        id="<?php echo esc_attr($iwbvel_tax_field_id); ?>-operator"
                        data-field="operator"
                        title="<?php esc_attr_e('Select Operator', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?>">
                        <?php foreach ($iwbvel_group_item['operators'] as $iwbvel_operator_name => $iwbvel_operator_label): ?>
                            <option value="<?php echo esc_attr($iwbvel_operator_name); ?>"><?php echo esc_html($iwbvel_operator_label); ?></option>
                        <?php endforeach; ?>
                    </select>

                    <select <?php echo ($iwbvel_tax_disabled) ? 'disabled="disabled"' : ''; ?>
                        class="iwbvel-select2-taxonomies iwbvel-select2-item"
                        data-output="<?php echo ($iwbvel_name == 'product_tag') ? 'slug' : 'term_id'; ?>"
                        data-field="value"
                        id="<?php echo esc_attr($iwbvel_tax_field_id); ?>"
                        multiple>
                    </select>

                    <?php if ($iwbvel_group_name === 'attribute' && isset($iwbvel_group_item['attribute_fields'])): ?>
                        <div style="width: 100%; float: left; padding: 8px 0 10px 200px; box-sizing: border-box;">
                            <?php foreach ($iwbvel_group_item['attribute_fields'] as $iwbvel_field_name => $iwbvel_field_config): ?>
                                <label for="<?php echo esc_attr($iwbvel_tax_field_id) . '-' . esc_attr($iwbvel_field_name); ?>" style="width: auto; padding-right: 8px; line-height: 28px; font-size: 13px;">
                                    <?php echo esc_html($iwbvel_field_config['label']); ?>
                                </label>
                                <select <?php echo ($iwbvel_tax_disabled) ? 'disabled="disabled"' : ''; ?>
                                    id="<?php echo esc_attr($iwbvel_tax_field_id) . '-' . esc_attr($iwbvel_field_name); ?>"
                                    data-field="attribute_<?php echo esc_attr($iwbvel_field_name); ?>"
                                    style="width: auto; height: 28px; font-size: 13px;">
                                    <?php foreach ($iwbvel_field_config['options'] as $iwbvel_value => $iwbvel_label): ?>
                                        <option value="<?php echo esc_attr($iwbvel_value); ?>"><?php echo esc_html($iwbvel_label); ?></option>
                                    <?php endforeach; ?>
                                </select>
                            <?php endforeach; ?>
                        </div>
                    <?php endif; ?>

                    <?php if ($iwbvel_tax_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>
            </div>
        <?php endforeach; ?>
    <?php else: ?>
        <div class="iwbvel-alert iwbvel-alert-warning">
            <span>
                <?php echo wp_kses(sprintf(
                    'There is not any added %s',
                    $iwbvel_group_name === 'taxonomy' ? esc_html__('Taxonomies', 'ithemeland-bulk-variation-editing-for-woocommerce') : esc_html__('Attributes', 'ithemeland-bulk-variation-editing-for-woocommerce')
                ), Sanitizer::allowed_html()); ?>
            </span>
        </div>
    <?php endif; ?>
<?php endforeach; ?>