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

<div class="iwbvel-meta-fields-right-item">
    <span class="iwbvel-meta-fields-name"><?php echo (!empty($meta_field['key'])) ? esc_html($meta_field['key']) : 'No Name!'; ?></span>
    <input type="hidden" class="iwbvel_meta_field_key_input" name="meta_field_key[]" value="<?php echo (!empty($meta_field['key'])) ? esc_attr($meta_field['key']) : ''; ?>">
    <input type="text" name="meta_field_title[]" class="iwbvel-meta-fields-title" placeholder="<?php esc_html_e('Enter field title ...', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?>" value="<?php echo (isset($meta_field['title'])) ? esc_attr($meta_field['title']) : ''; ?>">
    <?php if (isset($meta_field['type_disabled']) && $meta_field['type_disabled'] === true) : ?>
        <span class="iwbvel-meta-fields-type iwbvel-meta-fields-main-type"><?php echo esc_html(ucfirst($meta_field['main_type'])); ?></span>
        <span class="iwbvel-meta-fields-type iwbvel-meta-fields-sub-type"><?php echo esc_html(ucfirst($meta_field['sub_type'])); ?></span>
        <input type="hidden" name="meta_field_main_type[]" value="<?php echo esc_attr($meta_field['main_type']); ?>">
        <input type="hidden" name="meta_field_sub_type[]" value="<?php echo esc_attr($meta_field['sub_type']); ?>">
    <?php else : ?>
        <select class="iwbvel-meta-fields-type iwbvel-meta-fields-main-type" data-id="<?php echo (!empty($meta_field['key'])) ? esc_attr($meta_field['key']) : ''; ?>" name="meta_field_main_type[]" title="<?php esc_html_e('Select Type', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?>">
            <?php if (!empty($meta_fields_main_types)) : ?>
                <?php foreach ($meta_fields_main_types as $iwbvel_main_type_name => $iwbvel_main_type_label) : ?>
                    <option value="<?php echo esc_attr($iwbvel_main_type_name); ?>" <?php echo (isset($meta_field['main_type']) && $meta_field['main_type'] == $iwbvel_main_type_name) ? 'selected' : ''; ?>>
                        <?php echo esc_html($iwbvel_main_type_label); ?>
                    </option>
                <?php endforeach; ?>
            <?php endif; ?>
        </select>
        <select class="iwbvel-meta-fields-type iwbvel-meta-fields-sub-type <?php echo (isset($meta_field['main_type']) && $meta_field['main_type'] != 'textinput') ? 'iwbvel-hide' : ''; ?>" data-id="<?php echo (!empty($meta_field['key'])) ? esc_attr($meta_field['key']) : ''; ?>" name="meta_field_sub_type[]" title="<?php esc_html_e('Select Type', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?>">
            <?php if (!empty($meta_fields_sub_types)) : ?>
                <?php foreach ($meta_fields_sub_types as $iwbvel_sub_type_name => $iwbvel_sub_type_label) : ?>
                    <option value="<?php echo esc_attr($iwbvel_sub_type_name); ?>" <?php echo (isset($meta_field['sub_type']) && $meta_field['sub_type'] == $iwbvel_sub_type_name) ? 'selected' : ''; ?>>
                        <?php echo esc_html($iwbvel_sub_type_label); ?>
                    </option>
                <?php endforeach; ?>
            <?php endif; ?>
        </select>
        <div class="iwbvel-meta-fields-key-value <?php echo (empty($meta_field['main_type']) || (isset($meta_field['main_type']) && !in_array($meta_field['main_type'], ['select', 'array', 'radio']))) ? 'iwbvel-hide' : ''; ?>" data-id="<?php echo (!empty($meta_field['key'])) ? esc_attr($meta_field['key']) : ''; ?>">
            <input type="text" name="meta_field_key_value[]" value="<?php echo (!empty($meta_field['key_value'])) ? esc_attr($meta_field['key_value']) : '' ?>">
            <p><?php esc_html_e('key1=label1|key2=label2', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?></p>
        </div>
    <?php endif; ?>
    <button type="button" class="iwbvel-button iwbvel-button-flat iwbvel-meta-field-item-sortable-btn" title="<?php esc_html_e('Drag', 'ithemeland-bulk-variation-editing-for-woocommerce'); ?>">
        <i class="iwbvel-icon-menu1"></i>
    </button>
    <button type="button" class="iwbvel-button iwbvel-button-flat iwbvel-meta-field-remove">
        <i class="iwbvel-icon-x"></i>
    </button>
</div>