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

<div class="iwbvel-variations-attaching-items">
    <?php
    if (!empty($variation_ids)) :
        foreach ($variation_ids as $iwbvel_variation_id) :
            $iwbvel_variation_object = wc_get_product(intval($iwbvel_variation_id));
            if (!($iwbvel_variation_object instanceof \WC_Product_Variation)) {
                continue;
            }

            $iwbvel_attributes = $iwbvel_variation_object->get_attributes();
            if (!empty($iwbvel_attributes)) :
    ?>
                <div class="iwbvel-variations-attaching-item">
                    <input type="hidden" data-name="variation-id" value="<?php echo intval($iwbvel_variation_id); ?>">
                    <span>[#<?php echo esc_html($iwbvel_variation_id); ?>] - </span>
                    <?php
                    $iwbvel_j = 0;
                    foreach ($iwbvel_attributes as $iwbvel_attribute_name => $iwbvel_term_slug) :
                        $iwbvel_term = get_term_by('slug', $iwbvel_term_slug, $iwbvel_attribute_name);
                        if (!($iwbvel_term instanceof \WP_Term)) {
                            continue;
                        }
                    ?>
                        <input type="hidden" class="iwbvel-variations-possible-combination-item" data-attribute="<?php echo esc_attr($iwbvel_attribute_name); ?>" data-term-slug="<?php echo esc_attr($iwbvel_term_slug); ?>" data-term-id="<?php echo intval($iwbvel_term->term_id); ?>">
                        <span><?php echo esc_html($iwbvel_term->name) . " | "; ?></span>
                    <?php endforeach; ?>
                    <select data-name="term" data-attribute="<?php echo esc_attr($selected_attribute); ?>">
                        <?php foreach ($iwbvel_attribute_terms as $iwbvel_term_item) : ?>
                            <option value="<?php echo esc_attr($iwbvel_term_item->term_id); ?>"><?php echo esc_html($iwbvel_term_item->name); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
    <?php
            endif;
        endforeach;
    endif;
    ?>
</div>

<div class="iwbvel-variations-attach-container">
    <button type="button" class="iwbvel-button iwbvel-button-blue iwbvel-variations-attach-for-old-attribute"><i class="iwbvel-icon-check"></i> <?php esc_html_e('Attach', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?></button>
</div>