<!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
{% block sw_import_export_edit_profile_modal_mapping %}
<div class="sw-import-export-edit-profile-modal-mapping">

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_import_export_edit_profile_modal_mapping_toolbar %}
    <div class="sw-import-export-edit-profile-modal-mapping__toolbar">
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_import_export_edit_profile_modal_mapping_toolbar_search_field %}
        <sw-simple-search-field
            v-model:value="searchTerm"
            size="small"
            variant="form"
            :disabled="!mappingsExist"
            @search-term-change="onSearch"
        />
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_import_export_edit_profile_modal_mapping_toolbar_add_mapping %}
        <sw-button
            v-tooltip="{
                message: $tc('sw-import-export.profile.addMappingTooltipText'),
                disabled: addMappingEnabled,
                showOnDisabledElements: true
            }"
            class="sw-import-export-edit-profile-modal-mapping__add-action"
            variant="ghost"
            :disabled="profile.systemDefault || !addMappingEnabled"
            size="small"
            @click="onAddMapping"
        >
            {{ $tc('sw-import-export.profile.addMappingLabel') }}
        </sw-button>
        {% endblock %}
    </div>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_import_export_edit_profile_modal_mapping_grid %}
    <sw-data-grid
        v-if="mappingsExist"
        :data-source="sortedMappings"
        :compact-mode="false"
        :show-selection="false"
        :show-actions="!profile.systemDefault"
        :columns="mappingColumns"
        plain-appearance
        class="sw-import-export-edit-profile-modal-mapping__grid"
    >

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_import_export_edit_profile_modal_mapping_grid_csv_name_column %}
        <template #column-csvName="{ item, itemIndex }">
            <sw-text-field
                v-model:value="item.mappedKey"
                :name="`mappedKey-${itemIndex}`"
                :disabled="profile.systemDefault"
            />
        </template>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_import_export_edit_profile_modal_mapping_grid_entry_column %}
        <template #column-entry="{ item }">
            <sw-import-export-entity-path-select
                v-model:value="item.key"
                :languages="languages"
                :currencies="currencies"
                :entity-type="profile.sourceEntity"
                :disabled="profile.systemDefault"
                :custom-field-sets="customFieldSets"
            />
        </template>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_import_export_edit_profile_modal_mapping_grid_required_column %}
        <template #column-required="{ item }">
            <sw-switch-field
                v-show="isRequiredBySystem(item)"
                class="sw-import-export-edit-profile-modal-mapping__required-by-user-switch"
                :value="true"
                :disabled="true"
            />
            <sw-switch-field
                v-show="!isRequiredBySystem(item)"
                v-model:value="item.requiredByUser"
                class="sw-import-export-edit-profile-modal-mapping__required-by-user-switch"
                :disabled="profile.systemDefault"
            />
        </template>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_import_export_edit_profile_modal_mapping_grid_default_value_column %}
        <template #column-defaultValue="{ item, itemIndex }">
            <sw-switch-field
                v-model:value="item.useDefaultValue"
                :name="`useDefaultValue-${itemIndex}`"
                :disabled="isDefaultValueCheckboxDisabled()"
                class="sw-import-export-edit-profile-modal-mapping__default-value-switch"
            />

            <sw-text-field
                v-model:value="item.defaultValue"
                :name="`defaultValue-${itemIndex}`"
                :disabled="isDefaultValueTextFieldDisabled(item)"
            />
        </template>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_import_export_edit_profile_modal_mapping_grid_position_column %}
        <template #column-position="{ item, itemIndex }">

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_import_export_edit_profile_modal_mapping_grid_position_column_button_group %}
            <sw-button-group>
                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_import_export_edit_profile_modal_mapping_grid_position_column_button_group_up %}
                <sw-button
                    size="x-small"
                    square
                    :disabled="isFirstMapping(item) || !!searchTerm"
                    @click="updateSorting(itemIndex, 'up')"
                >
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_import_export_edit_profile_modal_mapping_grid_position_column_button_group_up_icon %}
                    <sw-icon
                        name="regular-chevron-up-xxs"
                        size="14px"
                    />
                    {% endblock %}
                </sw-button>
                {% endblock %}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_import_export_edit_profile_modal_mapping_grid_position_column_button_group_down %}
                <sw-button
                    size="x-small"
                    square
                    :disabled="isLastMapping(item) || !!searchTerm"
                    @click="updateSorting(itemIndex, 'down')"
                >
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_import_export_edit_profile_modal_mapping_grid_position_column_button_group_down_icon %}
                    <sw-icon
                        name="regular-chevron-down-xxs"
                        size="14px"
                    />
                    {% endblock %}
                </sw-button>
                {% endblock %}
            </sw-button-group>
            {% endblock %}
        </template>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_import_export_edit_profile_modal_mapping_grid_context_menu_delete %}
        <template #actions="{ item }">
            <sw-context-menu-item
                variant="danger"
                :disabled="profile.systemDefault"
                @click="onDeleteMapping(item.id)"
            >
                {{ $tc('sw-import-export.profile.deleteMappingLabel') }}
            </sw-context-menu-item>
        </template>
        {% endblock %}

    </sw-data-grid>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_import_export_edit_profile_modal_mapping_empty_state %}
    <sw-empty-state
        v-else
        class="sw-import-export-edit-profile-modal-mapping__empty-state"
        :title="$tc('sw-import-export.profile.mappingEmptyState')"
        :absolute="false"
    />
    {% endblock %}
</div>
{% endblock %}
