"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    AtomicCommerceRefineModal: ()=>AtomicCommerceRefineModal
});
const commerce_namespaceObject = require("@coveo/headless/commerce");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const boolean_converter_cjs_namespaceObject = require("../../../converters/boolean-converter.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 watch_cjs_namespaceObject = require("../../../decorators/watch.cjs");
const with_tailwind_styles_cjs_namespaceObject = require("../../../decorators/with-tailwind-styles.cjs");
const body_cjs_namespaceObject = require("../../common/refine-modal/body.cjs");
const filters_cjs_namespaceObject = require("../../common/refine-modal/filters.cjs");
const modal_cjs_namespaceObject = require("../../common/refine-modal/modal.cjs");
const sort_cjs_namespaceObject = require("../../common/refine-modal/sort.cjs");
const option_cjs_namespaceObject = require("../sort/option.cjs");
require("../atomic-commerce-facets/atomic-commerce-facets.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 AtomicCommerceRefineModal extends external_lit_namespaceObject.LitElement {
    initialize() {
        const searchOrListing = 'search' === this.bindings.interfaceElement.type ? (0, commerce_namespaceObject.buildSearch)(this.bindings.engine) : (0, commerce_namespaceObject.buildProductListing)(this.bindings.engine);
        this.summary = searchOrListing.summary();
        this.sort = searchOrListing.sort();
        this.facetGenerator = searchOrListing.facetGenerator();
        this.breadcrumbManager = searchOrListing.breadcrumbManager();
        this.watchEnabled();
    }
    watchEnabled() {
        if (this.isOpen) {
            if (this.querySelector('div[slot="facets"]')) return;
            this.appendChild(this.createFacetSlot());
        }
    }
    createFacetSlot() {
        const divSlot = document.createElement('div');
        divSlot.setAttribute('slot', 'facets');
        const facets = document.createElement('atomic-commerce-facets');
        facets.style.display = 'flex';
        facets.style.flexDirection = 'column';
        facets.style.gap = 'var(--atomic-refine-modal-facet-margin, 20px)';
        facets.collapseFacetsAfter = this.collapseFacetsAfter;
        divSlot.append(facets);
        return divSlot;
    }
    renderSort() {
        return (0, sort_cjs_namespaceObject.renderRefineModalSortSection)({
            props: {
                i18n: this.bindings.i18n,
                onSelect: this.onSelectSortOption
            }
        })((0, external_lit_namespaceObject.html)`${this.sortState.availableSorts.map((sort)=>(0, option_cjs_namespaceObject.renderCommerceSortOption)({
                props: {
                    i18n: this.bindings.i18n,
                    selected: this.sort.isSortedBy(sort),
                    sort
                }
            }))}`);
    }
    renderFilters() {
        if (0 === this.facetGeneratorState.length) return;
        const { i18n } = this.bindings;
        return (0, filters_cjs_namespaceObject.renderRefineModalFiltersSection)({
            props: {
                i18n,
                withFacets: true,
                withAutomaticFacets: false
            }
        })(this.breadcrumbManagerState.hasBreadcrumbs ? (0, filters_cjs_namespaceObject.renderRefineModalFiltersClearButton)({
            props: {
                i18n,
                onClick: ()=>this.breadcrumbManager.deselectAll()
            }
        }) : external_lit_namespaceObject.nothing);
    }
    render() {
        return (0, external_lit_namespaceObject.html)`${(0, modal_cjs_namespaceObject.renderRefineModal)({
            props: {
                i18n: this.bindings.i18n,
                i18nFooterButtonTextKey: 'view-products',
                host: this,
                isOpen: this.isOpen,
                onClose: ()=>{
                    this.isOpen = false;
                },
                title: this.bindings.i18n.t('sort-and-filter'),
                numberOfItems: this.summaryState.totalNumberOfProducts,
                openButton: this.openButton
            }
        })((0, body_cjs_namespaceObject.renderRefineModalBody)(this.bindings.i18n)((0, external_lit_namespaceObject.html)`
        ${this.renderSort()} ${this.renderFilters()}
      `))}`;
    }
    constructor(...args){
        super(...args), this.isOpen = false, this.collapseFacetsAfter = 0, this.onSelectSortOption = (e)=>{
            const select = e.composedPath()[0];
            this.sort.sortBy((0, option_cjs_namespaceObject.getSortByLabel)(select.value, this.sortState.availableSorts));
        };
    }
}
AtomicCommerceRefineModal.styles = [
    (0, external_lit_namespaceObject.css)`
      :host {
        position: absolute;
      }
    `
];
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof CommerceBindings ? Object : CommerceBindings)
], AtomicCommerceRefineModal.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicCommerceRefineModal.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        attribute: 'open-button',
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof HTMLElement ? Object : HTMLElement)
], AtomicCommerceRefineModal.prototype, "openButton", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter,
        reflect: true,
        attribute: 'is-open'
    })
], AtomicCommerceRefineModal.prototype, "isOpen", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'collapse-facets-after'
    })
], AtomicCommerceRefineModal.prototype, "collapseFacetsAfter", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('summary'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", Object)
], AtomicCommerceRefineModal.prototype, "summaryState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('sort'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof SortState ? Object : SortState)
], AtomicCommerceRefineModal.prototype, "sortState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('facetGenerator'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof FacetGeneratorState ? Object : FacetGeneratorState)
], AtomicCommerceRefineModal.prototype, "facetGeneratorState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('breadcrumbManager'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof BreadcrumbManagerState ? Object : BreadcrumbManagerState)
], AtomicCommerceRefineModal.prototype, "breadcrumbManagerState", void 0);
_ts_decorate([
    (0, watch_cjs_namespaceObject.watch)('isOpen'),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicCommerceRefineModal.prototype, "watchEnabled", null);
_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)
], AtomicCommerceRefineModal.prototype, "render", null);
AtomicCommerceRefineModal = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-commerce-refine-modal'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicCommerceRefineModal);
exports.AtomicCommerceRefineModal = __webpack_exports__.AtomicCommerceRefineModal;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicCommerceRefineModal"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
