<?php
if (!defined('ABSPATH')) exit; // Exit if accessed directly 
if (!empty($attributes) && is_array($attributes)) : ?>
    <?php foreach ($attributes as $iwbvel_attribute) : ?>
        <div class="iwbvel-product-attribute-item" data-name="<?php echo esc_attr($iwbvel_attribute->attribute_name); ?>" data-label="<?php echo esc_attr($iwbvel_attribute->attribute_label); ?>">
            <div class="iwbvel-product-attribute-item-label">
                <label for="iwbvel-attribute-<?php echo esc_attr($iwbvel_attribute->attribute_name); ?>" class="iwbvel-product-attribute-select-all-label">
                    <input type="checkbox" id="iwbvel-attribute-<?php echo esc_attr($iwbvel_attribute->attribute_name); ?>" class="iwbvel-product-attribute-select-all">
                    <i class="iwbvel-icon-check iwbvel-product-attribute-select-all-button" title="<?php echo esc_html__('Select All', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?>"></i>
                </label>

                <span><?php echo esc_html($iwbvel_attribute->attribute_label); ?></span>
                <button class="iwbvel-product-attribute-add-new-button" data-toggle="modal" data-target="#iwbvel-variations-new-attribute-term-modal" type="button" title="<?php esc_attr_e('Add New Term', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?>">
                    <span><?php esc_html_e('New', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?></span>
                </button>
            </div>
            <div class="iwbvel-product-attribute-item-middle-container">
                <?php
                $iwbvel_attribute_terms = get_terms([
                    'taxonomy' => "pa_{$iwbvel_attribute->attribute_name}",
                    'hide_empty' => false,
                ]);

                if (!empty($iwbvel_attribute_terms)) :
                ?>
                    <input type="hidden" name="attributes[pa_<?php echo esc_attr($iwbvel_attribute->attribute_name); ?>][name]" value="pa_<?php echo esc_attr($iwbvel_attribute->attribute_name); ?>">
                    <ul class="iwbvel-product-attribute-item-terms">
                        <?php
                        foreach ($iwbvel_attribute_terms as $iwbvel_attribute_term) {
                            include IWBVEL_VIEWS_DIR . "variations/add_variations/term-item.php";
                        };
                        ?>
                    </ul>
                <?php endif; ?>
                <div class="iwbvel-attribute-item-bottom-items disabled">
                    <label for="<?php echo esc_attr($iwbvel_attribute->attribute_name); ?>-visible-on-the-product-page">
                        <i class="iwbvel-icon-check-circle"></i>
                        <i class="iwbvel-icon-circle"></i>
                        <span><?php esc_html_e('Visible on the product page', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?></span>
                        <input type="checkbox" name="attributes[pa_<?php echo esc_attr($iwbvel_attribute->attribute_name); ?>][attribute_is_visible]" id="<?php echo esc_attr($iwbvel_attribute->attribute_name); ?>-visible-on-the-product-page" class="iwbvel-attribute-visible-on-the-product-page" value="yes">
                    </label>
                    <label for="<?php echo esc_attr($iwbvel_attribute->attribute_name); ?>-used-for-variations">
                        <i class="iwbvel-icon-check-circle"></i>
                        <i class="iwbvel-icon-circle"></i>
                        <span><?php esc_html_e('Used for variations', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?></span>
                        <input type="checkbox" name="attributes[pa_<?php echo esc_attr($iwbvel_attribute->attribute_name); ?>][used_for_variations]" id="<?php echo esc_attr($iwbvel_attribute->attribute_name); ?>-used-for-variations" class="iwbvel-attribute-used-for-variations" value="yes">
                    </label>
                </div>
                <div class="iwbvel-variation-add-new-term-loading">
                    <p><img src="<?php echo esc_url(IWBVEL_IMAGES_URL . 'loading-2.gif'); ?>" width="26"></p>
                </div>
            </div>
        </div>
    <?php endforeach; ?>
<?php endif; ?>