<!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
{% block sw_product_properties %}
<sw-inherit-wrapper
    v-if="properties"
    v-model:value="product.properties"
    class="sw-product-properties"
    :is-association="isAssociation"
    :disabled="disabled || undefined"
    :inherited-value="parentProduct.properties"
>
    <template #content="{ isInherited, updateCurrentValue, isInheritField, restoreInheritance, removeInheritance }">
        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_product_properties_card %}
        <sw-card
            class="sw-product-properties__card"
            :class="{
                'is--inherited': isInherited,
                'is--disabled': disabled,
            }"
            position-identifier="sw-product-properties"
            :is-loading="isLoading"
        >
            <template #title>
                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_product_properties_card_title %}
                <div
                    class="sw-card__title"
                    :class="{ 'is--inherited': isInherited }"
                >
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_properties_card_title_icon %}
                    <sw-inheritance-switch
                        v-if="isInheritField && showInheritanceSwitcher"
                        class="sw-inherit-wrapper__inheritance-icon"
                        :is-inherited="isInherited"
                        :disabled="!acl.can('product.editor') || undefined"
                        @inheritance-restore="restoreInheritance"
                        @inheritance-remove="removeInheritance"
                    />
                    {% endblock %}

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_properties_card_title_text %}
                    {{ $tc('sw-product.properties.cardTitle') }}
                    {% endblock %}
                </div>
                {% endblock %}
            </template>

            <template
                v-if="productHasProperties"
                #grid
            >
                <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                {% block sw_product_properties_filled_state %}
                <sw-container rows="auto auto">
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_properties_filled_state_header %}
                    <sw-card-section
                        secondary
                        divider="bottom"
                    >
                        <sw-container
                            columns="1fr auto"
                            gap="0 15px"
                        >
                            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                            {% block sw_product_properties_filled_state_header_form_control %}
                            <sw-simple-search-field
                                v-model:value="searchTerm"
                                variant="form"
                                size="small"
                                :placeholder="$tc('sw-product.properties.placeholderSearchAddedProperties')"
                                :disabled="isPropertiesLoading || undefined"
                                @search-term-change="onChangeSearchTerm"
                            />
                            {% endblock %}

                            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                            {% block sw_product_properties_filled_state_header_button %}
                            <sw-button
                                v-tooltip="{
                                    message: $tc('sw-privileges.tooltip.warning'),
                                    disabled: acl.can('product.editor'),
                                    showOnDisabledElements: true
                                }"
                                class="sw-product-properties__button-add-property"
                                variant="ghost"
                                size="small"
                                :disabled="!acl.can('product.editor') || undefined"
                                @click="turnOnAddPropertiesModal"
                            >
                                {{ $tc('sw-product.properties.buttonAddProperty') }}
                            </sw-button>
                            {% endblock %}
                        </sw-container>
                    </sw-card-section>
                    {% endblock %}

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_properties_filled_state_body_filled_state %}
                    <sw-entity-listing
                        v-if="properties.length > 0"
                        ref="entityListing"
                        class="sw-product-properties__list"
                        detail-route="sw.property.detail"
                        identifier="sw-product-properties-list"
                        plain-appearance
                        :items="properties"
                        :data-source="properties"
                        :columns="propertyColumns"
                        :repository="propertyGroupRepository"
                        :full-page="false"
                        :show-settings="false"
                        :allow-column-edit="false"
                        :allow-inline-edit="false"
                        :allow-view="acl.can('product.viewer') || undefined"
                        :allow-edit="acl.can('property.editor') || undefined"
                        :allow-delete="acl.can('product.deleter') || undefined"
                    >
                        <template #column-values="{ item }">
                            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                            {% block sw_product_properties_filled_state_body_filled_state_column_values %}
                            <div
                                v-for="option in item.options"
                                :key="option.id"
                                class="sw-product-properties-list__column-values"
                            >
                                <sw-label
                                    size="medium"
                                    :dismissable="acl.can('product.deleter')"
                                    @dismiss="onDeletePropertyValue(option)"
                                >
                                    {{ option.translated.name }}
                                </sw-label>
                            </div>
                            {% endblock %}
                        </template>

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

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

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_properties_filled_state_body_empty_state %}
                    <sw-empty-state
                        v-if="properties.length <= 0"
                        class="sw-product-properties__empty-state has--no-search-result"
                        :absolute="false"
                        :show-description="false"
                        :title="$tc('sw-product.properties.titleEmptyStateList')"
                    >
                        <template #icon>
                            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                            {% block sw_product_properties_filled_state_body_empty_state_image %}
                            <img
                                :src="assetFilter('/administration/static/img/empty-states/products-empty-state.svg')"
                                :alt="$tc('sw-product.properties.titleEmptyStateList')"
                            >
                            {% endblock %}
                        </template>
                    </sw-empty-state>
                    {% endblock %}

                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_properties_filled_state_body_loading_state %}
                    <sw-loader v-if="isPropertiesLoading" />
                    {% endblock %}
                </sw-container>
                {% endblock %}
            </template>

            <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
            {% block sw_product_properties_empty_state %}
            <sw-empty-state
                v-if="!productHasProperties"
                class="sw-product-properties__empty-state has--no-properties"
                :absolute="false"
                :show-description="false"
                :title="$tc('sw-product.properties.titleEmptyState')"
            >
                <template #icon>
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_properties_empty_state_image %}
                    <img
                        :src="assetFilter('/administration/static/img/empty-states/products-empty-state.svg')"
                        :alt="$tc('sw-product.properties.titleEmptyState')"
                    >
                    {% endblock %}
                </template>

                <template #actions>
                    <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
                    {% block sw_product_properties_empty_state_button %}
                    <sw-button
                        v-tooltip="{
                            message: $tc('sw-privileges.tooltip.warning'),
                            disabled: acl.can('product.editor'),
                            showOnDisabledElements: true
                        }"
                        variant="ghost"
                        :disabled="!acl.can('product.editor') || undefined"
                        @click="turnOnAddPropertiesModal"
                    >
                        {{ $tc('sw-product.properties.buttonAddProperties') }}
                    </sw-button>
                    {% endblock %}
                </template>
            </sw-empty-state>
            {% endblock %}
        </sw-card>
        {% endblock %}

        <!-- eslint-disable-next-line sw-deprecation-rules/no-twigjs-blocks -->
        {% block sw_product_properties_add_properties_modal %}
        <sw-product-add-properties-modal
            v-if="showAddPropertiesModal"
            :new-properties="newProperties"
            :properties-available="propertiesAvailable"
            @modal-cancel="onCancelAddPropertiesModal"
            @modal-save="onSaveAddPropertiesModal($event, updateCurrentValue)"
        />
        {% endblock %}
    </template>
</sw-inherit-wrapper>
{% endblock %}
