<!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
{% block sw_custom_field_list %}
<sw-card
    class="sw-custom-field-list"
    position-identifier="sw-custom-field-list"
>
    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_custom_field_list_toolbar %}
    <div class="sw-custom-field-list__toolbar">
        <sw-container
            columns="1fr 32px minmax(100px, 200px)"
            gap="0 10px"
        >
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_custom_field_list_toolbar_searchfield %}
            <sw-simple-search-field
                v-model:value="term"
                size="small"
                variant="form"
                :delay="500"
                @search-term-change="onSearchTermChange"
            />
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_custom_field_list_toolbar_delete %}
            <sw-button
                v-tooltip.bottom="{
                    message: $tc('sw-privileges.tooltip.warning'),
                    disabled: acl.can('custom_field.editor'),
                    showOnDisabledElements: true
                }"
                :disabled="deleteButtonDisabled || !acl.can('custom_field.editor') || undefined"
                square
                size="small"
                class="sw-custom-field-list__delete-button"
                @click="onDeleteCustomFields"
            >
                <sw-icon
                    name="regular-trash"
                    small
                />
            </sw-button>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_custom_field_list_toolbar_add %}
            <sw-button
                v-tooltip.bottom="{
                    message: $tc('sw-privileges.tooltip.warning'),
                    disabled: acl.can('custom_field.editor'),
                    showOnDisabledElements: true
                }"
                :disabled="set.isLoading || !acl.can('custom_field.editor') || undefined"
                size="small"
                class="sw-custom-field-list__add-button"
                @click="onAddCustomField(set)"
            >
                {{ $tc('sw-settings-custom-field.set.detail.addCustomField') }}
            </sw-button>
            {% endblock %}
        </sw-container>
    </div>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_custom_field_list_grid %}
    <sw-grid
        v-if="(customFields && customFields.length > 0) || term"
        ref="grid"
        class="sw-custom-field-list__grid"
        :items="customFields"
        :is-fullpage="false"
        table
        :selectable="acl.can('custom_field.editor')"
        @inline-edit-finish="onInlineEditFinish"
        @inline-edit-cancel="onInlineEditCancel"
        @sw-grid-select-item="selectionChanged"
        @sw-grid-select-all="selectionChanged"
    >
        <template
            #columns="{ item }"
        >

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_custom_field_list_grid_column_label %}
            <sw-grid-column
                data-index="label"
                truncate
                flex="minmax(150px, 1fr)"
                :label="$tc('sw-settings-custom-field.customField.list.labelCustomFieldLabel')"
            >
                <span
                    class="sw-custom-field-list__custom-field-label"
                    role="textbox"
                    tabindex="0"
                    @click="onCustomFieldEdit(item)"
                    @keydown.enter="onCustomFieldEdit(item)"
                >
                    {{ getInlineSnippet(item.config.label) || item.name }}
                </span>

                <template #inline-edit>
                    <sw-text-field
                        :value="getInlineSnippet(item.config.label) || item.name"
                        disabled
                    />
                </template>
            </sw-grid-column>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_custom_field_list_grid_column_type %}
            <sw-grid-column
                data-index="type"
                truncate
                flex="minmax(150px, 200px)"
                :label="$tc('sw-settings-custom-field.customField.list.labelCustomFieldType')"
            >
                {{ $tc(`sw-settings-custom-field.types.${item.config.customFieldType || item.type}`) }}

                <template #inline-edit>
                    <sw-text-field
                        :value="$tc(`sw-settings-custom-field.types.${item.config.customFieldType || item.type}`)"
                        disabled
                    />
                </template>
            </sw-grid-column>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_custom_field_list_grid_column_custom_field_position %}
            <sw-grid-column
                data-index="position"
                flex="minmax(50px, 100px)"
                :editable="acl.can('custom_field.editor')"
                :label="$tc('sw-settings-custom-field.customField.list.labelCustomFieldPosition')"
            >
                {{ item.config.customFieldPosition }}

                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_custom_field_list_grid_column_custom_field_position_edit %}
                <template #inline-edit>
                    <sw-number-field
                        v-model:value="item.config.customFieldPosition"
                        number-type="int"
                    />
                </template>
                {% endblock %}
            </sw-grid-column>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_custom_field_list_grid_column_actions %}
            <sw-grid-column
                flex="minmax(100px, 100px)"
                align="center"
            >
                <sw-context-button>
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_custom_field_list_grid_column_actions_edit %}
                    <sw-context-menu-item
                        class="sw-custom-field-list__edit-action"
                        :disabled="item.isDeleted || !acl.can('custom_field.editor') || undefined"
                        @click="onCustomFieldEdit(item)"
                    >
                        {{ $tc('sw-settings-custom-field.customField.list.contextMenuCustomFieldView') }}
                    </sw-context-menu-item>
                    {% endblock %}

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_custom_field_list_grid_column_actions_reset_delete %}
                    <sw-context-menu-item
                        v-if="item.isDeleted"
                        variant="success"
                        :disabled="!acl.can('custom_field.editor') || undefined"
                    >
                        {{ $tc('sw-settings-custom-field.customField.list.contextMenuCustomFieldResetDelete') }}
                    </sw-context-menu-item>
                    {% endblock %}

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_custom_field_list_grid_column_actions_delete %}
                    <sw-context-menu-item
                        v-else
                        variant="danger"
                        class="sw-custom-field-list__delete-action"
                        :disabled="!acl.can('custom_field.editor')"
                        @click="onCustomFieldDelete(item)"
                    >
                        {{ $tc('sw-settings-custom-field.customField.list.contextMenuCustomFieldDelete') }}
                    </sw-context-menu-item>
                    {% endblock %}
                </sw-context-button>
            </sw-grid-column>
            {% endblock %}
        </template>

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_custom_field_list_grid_pagination %}
        <template #pagination>
            <sw-pagination
                :limit="limit"
                :page="page"
                :auto-hide="false"
                :total="customFields.total"
                :steps="[limit]"
                @page-change="onPageChange"
            />
        </template>
        {% endblock %}
    </sw-grid>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_custom_field_list_empty_state %}
    <sw-empty-state
        v-else-if="!set.isLoading"
        :absolute="false"
        :title="$tc('sw-settings-custom-field.set.detail.messageCustomFieldsEmpty')"
    />
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_custom_field_list_custom_field_detail %}
    <sw-custom-field-detail
        v-if="currentCustomField"
        :set="set"
        :current-custom-field="currentCustomField"
        @custom-field-edit-save="onSaveCustomField"
        @custom-field-edit-cancel="onCancelCustomField"
    />
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_custom_field_list_custom_field_delete %}
    <sw-modal
        v-if="deleteCustomField"
        :title="$tc('sw-settings-custom-field.customField.list.titleDeleteAction', deleteCustomField.length)"
        variant="small"
        @modal-close="onCancelDeleteCustomField"
    >

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_custom_field_list_custom_field_delete_text %}
        <p class="sw-custom-field-delete__description">
            {{ $tc('sw-settings-custom-field.customField.list.textDeleteActionConfirmation', deleteCustomField.length, { count: deleteCustomField.length }) }}
        </p>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_custom_field_list_custom_field_delete_actions %}
        <template #modal-footer>
            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_custom_field_list_custom_field_delete_action_cancel %}
            <sw-button
                size="small"
                @click="onCancelDeleteCustomField"
            >
                {{ $tc('global.default.cancel') }}
            </sw-button>
            {% endblock %}

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_custom_field_list_custom_field_delete_action_confirm %}
            <sw-button
                variant="danger"
                size="small"
                @click="onDeleteCustomField"
            >
                {{ $tc('global.default.delete') }}
            </sw-button>
            {% endblock %}
        </template>
        {% endblock %}
    </sw-modal>
    {% endblock %}

    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
    {% block sw_custom_field_list_loader %}
    <sw-loader v-if="isLoading" />
    {% endblock %}
</sw-card>
{% endblock %}
