"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    AtomicCommerceProductList: ()=>AtomicCommerceProductList
});
const bueno_namespaceObject = require("@coveo/bueno");
const commerce_namespaceObject = require("@coveo/headless/commerce");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const keyed_js_namespaceObject = require("lit/directives/keyed.js");
const map_js_namespaceObject = require("lit/directives/map.js");
const ref_js_namespaceObject = require("lit/directives/ref.js");
const when_js_namespaceObject = require("lit/directives/when.js");
const product_template_provider_cjs_namespaceObject = require("../product-list/product-template-provider.cjs");
const item_placeholders_cjs_namespaceObject = require("../../common/atomic-result-placeholder/item-placeholders.cjs");
const store_cjs_namespaceObject = require("../../common/interface/store.cjs");
const display_wrapper_cjs_namespaceObject = require("../../common/item-list/display-wrapper.cjs");
const grid_layout_cjs_namespaceObject = require("../../common/item-list/grid-layout.cjs");
const item_list_cjs_namespaceObject = require("../../common/item-list/item-list.cjs");
const item_list_common_cjs_namespaceObject = require("../../common/item-list/item-list-common.cjs");
const grid_display_tw_css_cjs_namespaceObject = require("../../common/item-list/styles/grid-display.tw.css.cjs");
var grid_display_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(grid_display_tw_css_cjs_namespaceObject);
const list_display_tw_css_cjs_namespaceObject = require("../../common/item-list/styles/list-display.tw.css.cjs");
var list_display_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(list_display_tw_css_cjs_namespaceObject);
const placeholders_tw_css_cjs_namespaceObject = require("../../common/item-list/styles/placeholders.tw.css.cjs");
var placeholders_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(placeholders_tw_css_cjs_namespaceObject);
const table_display_tw_css_cjs_namespaceObject = require("../../common/item-list/styles/table-display.tw.css.cjs");
var table_display_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(table_display_tw_css_cjs_namespaceObject);
const table_layout_cjs_namespaceObject = require("../../common/item-list/table-layout.cjs");
const item_layout_utils_cjs_namespaceObject = require("../../common/layout/item-layout-utils.cjs");
const bind_state_cjs_namespaceObject = require("../../../decorators/bind-state.cjs");
const binding_guard_cjs_namespaceObject = require("../../../decorators/binding-guard.cjs");
const bindings_cjs_namespaceObject = require("../../../decorators/bindings.cjs");
const error_guard_cjs_namespaceObject = require("../../../decorators/error-guard.cjs");
const with_tailwind_styles_cjs_namespaceObject = require("../../../decorators/with-tailwind-styles.cjs");
const children_update_complete_mixin_cjs_namespaceObject = require("../../../mixins/children-update-complete-mixin.cjs");
const accessibility_utils_cjs_namespaceObject = require("../../../utils/accessibility-utils.cjs");
const utils_cjs_namespaceObject = require("../../../utils/utils.cjs");
require("../atomic-product/atomic-product.cjs");
require("../atomic-product-template/atomic-product-template.cjs");
function _ts_decorate(decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
    else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function _ts_metadata(k, v) {
    if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v);
}
class AtomicCommerceProductList extends (0, children_update_complete_mixin_cjs_namespaceObject.ChildrenUpdateCompleteMixin)(external_lit_namespaceObject.LitElement) {
    async setRenderFunction(productRenderingFunction) {
        this.itemRenderingFunction = productRenderingFunction;
    }
    initialize() {
        this.validateProps();
        this.initSearchOrListing();
        this.initSummary();
        this.initProductTemplateProvider();
        this.initProductListCommon();
        this.createSelectChildProductListener();
        (0, store_cjs_namespaceObject.createAppLoadedListener)(this.bindings.store, (isAppLoaded)=>{
            this.isAppLoaded = isAppLoaded;
        });
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.unsubscribeSummary?.();
        this.removeEventListener('atomic/selectChildProduct', this.selectChildProductCallback);
    }
    async updated(changedProperties) {
        super.updated(changedProperties);
        if (changedProperties.has('searchOrListingState')) {
            const oldState = changedProperties.get('searchOrListingState');
            if (!oldState?.isLoading && this.searchOrListingState.isLoading) this.isEveryProductReady = false;
        }
        await this.updateProductsReadyState();
    }
    async updateProductsReadyState() {
        if (this.isAppLoaded && !this.isEveryProductReady && this.summaryState?.firstRequestExecuted && this.searchOrListingState?.products?.length > 0) {
            await this.getUpdateComplete();
            this.isEveryProductReady = true;
        }
    }
    render() {
        return (0, external_lit_namespaceObject.html)`${(0, item_list_cjs_namespaceObject.renderItemList)({
            props: {
                hasError: this.summaryState.hasError,
                hasItems: this.summaryState.hasProducts,
                hasTemplate: this.resultTemplateRegistered,
                firstRequestExecuted: this.summaryState.firstRequestExecuted,
                templateHasError: this.templateHasError
            }
        })((0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)(this.templateHasError, ()=>(0, external_lit_namespaceObject.html)`<slot></slot>`, ()=>{
            const listClasses = this.computeListDisplayClasses();
            const productClasses = `${listClasses} ${!this.isEveryProductReady && 'hidden'}`;
            return (0, external_lit_namespaceObject.html)`
            ${(0, when_js_namespaceObject.when)(this.isAppLoaded, ()=>(0, display_wrapper_cjs_namespaceObject.renderDisplayWrapper)({
                    props: {
                        listClasses: productClasses,
                        display: this.display
                    }
                })((0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)('grid' === this.display, ()=>this.renderGrid(), ()=>(0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)('list' === this.display, ()=>this.renderList(), ()=>this.renderTable())}`)}`))}
            ${(0, when_js_namespaceObject.when)(!this.isEveryProductReady, ()=>(0, display_wrapper_cjs_namespaceObject.renderDisplayWrapper)({
                    props: {
                        listClasses,
                        display: this.display
                    }
                })((0, item_placeholders_cjs_namespaceObject.renderItemPlaceholders)({
                    props: {
                        density: this.density,
                        display: this.display,
                        imageSize: this.imageSize,
                        numberOfPlaceholders: this.numberOfPlaceholders
                    }
                })))}
          `;
        })}`)}`;
    }
    validateProps() {
        new bueno_namespaceObject.Schema({
            density: new bueno_namespaceObject.StringValue({
                constrainTo: [
                    'normal',
                    'comfortable',
                    'compact'
                ]
            }),
            display: new bueno_namespaceObject.StringValue({
                constrainTo: [
                    'grid',
                    'list',
                    'table'
                ]
            }),
            imageSize: new bueno_namespaceObject.StringValue({
                constrainTo: [
                    'small',
                    'large',
                    'icon',
                    'none'
                ]
            }),
            numberOfPlaceholders: new bueno_namespaceObject.NumberValue({
                min: 0
            })
        }).validate({
            density: this.density,
            display: this.display,
            imageSize: this.imageSize,
            numberOfPlaceholders: this.numberOfPlaceholders
        });
    }
    initSearchOrListing() {
        if ('product-listing' === this.bindings.interfaceElement.type) this.searchOrListing = (0, commerce_namespaceObject.buildProductListing)(this.bindings.engine);
        else this.searchOrListing = (0, commerce_namespaceObject.buildSearch)(this.bindings.engine);
    }
    initSummary() {
        this.summary = this.searchOrListing.summary();
        this.unsubscribeSummary = this.summary.subscribe(()=>{
            this.summaryState = this.summary.state;
            if (this.summaryState.firstRequestExecuted) this.bindings.store.unsetLoadingFlag(this.loadingFlag);
        });
    }
    initProductTemplateProvider() {
        this.productTemplateProvider = new product_template_provider_cjs_namespaceObject.ProductTemplateProvider({
            includeDefaultTemplate: true,
            templateElements: Array.from(this.querySelectorAll('atomic-product-template')),
            getResultTemplateRegistered: ()=>this.resultTemplateRegistered,
            getTemplateHasError: ()=>this.templateHasError,
            setResultTemplateRegistered: (value)=>{
                this.resultTemplateRegistered = value;
            },
            setTemplateHasError: (value)=>{
                this.templateHasError = value;
            }
        });
    }
    initProductListCommon() {
        this.productListCommon = new item_list_common_cjs_namespaceObject.ItemListCommon({
            engineSubscribe: this.bindings.engine.subscribe,
            getCurrentNumberOfItems: ()=>this.searchOrListingState.products.length,
            getIsLoading: ()=>this.searchOrListingState.isLoading,
            host: this,
            loadingFlag: this.loadingFlag,
            nextNewItemTarget: this.focusTarget,
            store: this.bindings.store
        });
    }
    createSelectChildProductListener() {
        this.addEventListener('atomic/selectChildProduct', this.selectChildProductCallback);
    }
    selectChildProductCallback(event) {
        event.stopPropagation();
        const child = event.detail.child;
        this.searchOrListing.promoteChildToParent(child);
    }
    computeListDisplayClasses() {
        const displayPlaceholders = !(this.isAppLoaded && this.isEveryProductReady);
        return (0, item_layout_utils_cjs_namespaceObject.getItemListDisplayClasses)(this.display, this.density, this.imageSize, this.searchOrListingState?.isLoading, displayPlaceholders);
    }
    renderGrid() {
        return (0, external_lit_namespaceObject.html)`${(0, map_js_namespaceObject.map)(this.searchOrListingState.products, (product, index)=>(0, grid_layout_cjs_namespaceObject.renderGridLayout)({
                props: {
                    item: {
                        ...product,
                        title: product.ec_name ?? ''
                    },
                    selectorForItem: 'atomic-product',
                    setRef: (element)=>{
                        element instanceof HTMLElement && this.productListCommon.setNewResultRef(element, index);
                    }
                }
            })((0, external_lit_namespaceObject.html)`${(0, keyed_js_namespaceObject.keyed)(this.productListCommon.getResultId(product.permanentid, this.searchOrListingState.responseId, this.density, this.imageSize), (0, external_lit_namespaceObject.html)`<atomic-product
            .content=${this.productTemplateProvider.getTemplateContent(product)}
            .density=${this.density}
            .display=${this.display}
            .imageSize=${this.imageSize}
            .interactiveProduct=${this.searchOrListing.interactiveProduct({
                options: {
                    product
                }
            })}
            .linkContent=${this.productTemplateProvider.getLinkTemplateContent(product)}
            .loadingFlag=${this.loadingFlag}
            .product=${product}
            .renderingFunction=${this.itemRenderingFunction}
            .store=${this.bindings.store}
          ></atomic-product>`)}`))}`;
    }
    renderList() {
        return (0, external_lit_namespaceObject.html)`${(0, map_js_namespaceObject.map)(this.searchOrListingState.products, (product, index)=>(0, external_lit_namespaceObject.html)`${(0, keyed_js_namespaceObject.keyed)(this.productListCommon.getResultId(product.permanentid, this.searchOrListingState.responseId, this.density, this.imageSize), (0, external_lit_namespaceObject.html)`<atomic-product
          part="outline"
          ${(0, ref_js_namespaceObject.ref)((element)=>element instanceof HTMLElement && this.productListCommon.setNewResultRef(element, index))}
          .content=${this.productTemplateProvider.getTemplateContent(product)}
          .density=${this.density}
          .display=${this.display}
          .imageSize=${this.imageSize}
          .interactiveProduct=${this.searchOrListing.interactiveProduct({
                options: {
                    product
                }
            })}
          .linkContent=${this.productTemplateProvider.getLinkTemplateContent(product)}
          .loadingFlag=${this.loadingFlag}
          .product=${product}
          .renderingFunction=${this.itemRenderingFunction}
          .store=${this.bindings.store}
        ></atomic-product>`)}`)}`;
    }
    renderTable() {
        return (0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)(this.summaryState.hasProducts, ()=>{
            const firstItem = this.searchOrListingState.products[0];
            const listClasses = this.computeListDisplayClasses();
            const templateContentForFirstItem = this.productTemplateProvider.getTemplateContent(firstItem);
            return (0, table_layout_cjs_namespaceObject.renderTableLayout)({
                props: {
                    firstItem,
                    host: this,
                    itemRenderingFunction: this.itemRenderingFunction,
                    label: this.bindings.i18n.t('view-products'),
                    listClasses,
                    logger: this.bindings.engine.logger,
                    templateContentForFirstItem
                }
            })((0, external_lit_namespaceObject.html)`${(0, map_js_namespaceObject.map)(this.searchOrListingState.products, (product, index)=>{
                const key = this.productListCommon.getResultId(product.permanentid, this.searchOrListingState.responseId, this.density, this.imageSize);
                return (0, table_layout_cjs_namespaceObject.renderTableRow)({
                    props: {
                        key,
                        rowIndex: index,
                        setRef: (element)=>element instanceof HTMLElement && this.productListCommon.setNewResultRef(element, index)
                    }
                })((0, external_lit_namespaceObject.html)`${(0, table_layout_cjs_namespaceObject.renderTableData)({
                    props: {
                        firstItem,
                        key,
                        itemRenderingFunction: this.itemRenderingFunction,
                        templateContentForFirstItem,
                        renderItem: (content)=>(0, external_lit_namespaceObject.html)`${(0, keyed_js_namespaceObject.keyed)(key, (0, external_lit_namespaceObject.html)`<atomic-product
                        .content=${content}
                        .density=${this.density}
                        .display=${this.display}
                        .imageSize=${this.imageSize}
                        .interactiveProduct=${this.searchOrListing.interactiveProduct({
                                options: {
                                    product
                                }
                            })}
                        .linkContent=${this.productTemplateProvider.getLinkTemplateContent(product)}
                        .loadingFlag=${this.loadingFlag}
                        .product=${product}
                        .store=${this.bindings.store}
                      ></atomic-product>`)}`
                    }
                })}`);
            })}`);
        }, ()=>external_lit_namespaceObject.nothing)}`;
    }
    get focusTarget() {
        if (!this.nextNewResultTarget) this.nextNewResultTarget = new accessibility_utils_cjs_namespaceObject.FocusTargetController(this, this.bindings);
        return this.nextNewResultTarget;
    }
    constructor(...args){
        super(...args), this.loadingFlag = (0, utils_cjs_namespaceObject.randomID)('firstProductLoaded-'), this.isAppLoaded = false, this.isEveryProductReady = false, this.resultTemplateRegistered = false, this.templateHasError = false, this.density = 'normal', this.display = 'grid', this.imageSize = 'small', this.numberOfPlaceholders = 24;
    }
}
AtomicCommerceProductList.styles = [
    placeholders_tw_css_cjs_default(),
    table_display_tw_css_cjs_default(),
    list_display_tw_css_cjs_default(),
    grid_display_tw_css_cjs_default(),
    (0, external_lit_namespaceObject.css)`
      @reference '../../../utils/tailwind.global.tw.css';
      :host {
        .result-link {
          @apply link-style;
        }

        .result-grid {
          grid-template-columns: repeat(5, minmax(0, 1fr));
          justify-items: center;

          & a {
            justify-content: center;
          }
        }

        .result-list {
          display: flex;
          flex-direction: column;

          & .result-item {
            width: 100%;
            max-width: 600px;
            display: flex;
            flex-wrap: wrap;

            & .result-details {
              align-content: center;
            }
          }
        }
      }

      @media (width >= theme(--breakpoint-desktop)) {
        :host .result-grid {
          display: grid;
        }
      }

      @media not all and (width >= theme(--breakpoint-desktop)) {
        :host .result-grid {
          display: flex;
          flex-direction: column;
        }
      }
    `
];
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof CommerceBindings ? Object : CommerceBindings)
], AtomicCommerceProductList.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicCommerceProductList.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicCommerceProductList.prototype, "isAppLoaded", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicCommerceProductList.prototype, "isEveryProductReady", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicCommerceProductList.prototype, "resultTemplateRegistered", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)()
], AtomicCommerceProductList.prototype, "templateHasError", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('searchOrListing'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", Object)
], AtomicCommerceProductList.prototype, "searchOrListingState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('summary'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", Object)
], AtomicCommerceProductList.prototype, "summaryState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: String
    }),
    _ts_metadata("design:type", "u" < typeof ItemDisplayDensity ? Object : ItemDisplayDensity)
], AtomicCommerceProductList.prototype, "density", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: String
    }),
    _ts_metadata("design:type", "u" < typeof ItemDisplayLayout ? Object : ItemDisplayLayout)
], AtomicCommerceProductList.prototype, "display", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'image-size',
        type: String
    }),
    _ts_metadata("design:type", "u" < typeof ItemDisplayImageSize ? Object : ItemDisplayImageSize)
], AtomicCommerceProductList.prototype, "imageSize", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'number-of-placeholders',
        type: Number
    })
], AtomicCommerceProductList.prototype, "numberOfPlaceholders", void 0);
_ts_decorate([
    (0, binding_guard_cjs_namespaceObject.bindingGuard)(),
    (0, error_guard_cjs_namespaceObject.errorGuard)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicCommerceProductList.prototype, "render", null);
AtomicCommerceProductList = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-commerce-product-list'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicCommerceProductList);
exports.AtomicCommerceProductList = __webpack_exports__.AtomicCommerceProductList;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicCommerceProductList"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
