"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__, {
    AtomicIpxRefineModal: ()=>AtomicIpxRefineModal
});
const headless_namespaceObject = require("@coveo/headless");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const facet_common_cjs_namespaceObject = require("../../common/facets/facet-common.cjs");
const popover_type_cjs_namespaceObject = require("../../common/facets/popover/popover-type.cjs");
const store_cjs_namespaceObject = require("../../common/interface/store.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 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 utils_cjs_namespaceObject = require("../../../utils/utils.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 AtomicIpxRefineModal extends external_lit_namespaceObject.LitElement {
    initialize() {
        this.breadcrumbManager = (0, headless_namespaceObject.buildBreadcrumbManager)(this.bindings.engine);
        this.querySummary = (0, headless_namespaceObject.buildQuerySummary)(this.bindings.engine);
        this.watchEnabled();
    }
    watchEnabled() {
        if (this.isOpen) this.createFacetSlotIfAbsent();
    }
    createFacetSlotIfAbsent() {
        if (this.querySelector('div[slot="facets"]')) return;
        this.appendChild(this.createFacetSlot());
    }
    createFacetSlot() {
        const divSlot = document.createElement('div');
        divSlot.setAttribute('slot', 'facets');
        this.addFacetColumnStyling(divSlot);
        const facets = this.bindings.store.getFacetElements().sort(utils_cjs_namespaceObject.sortByDocumentPosition);
        const clonedFacets = this.cloneFacets(facets);
        (0, facet_common_cjs_namespaceObject.collapseFacetsAfter)(clonedFacets, this.collapseFacetsAfter);
        divSlot.append(...clonedFacets);
        return divSlot;
    }
    cloneFacets(facets) {
        return facets.map((facet, i)=>{
            const clone = facet.cloneNode(true);
            clone.classList.remove(popover_type_cjs_namespaceObject.popoverClass);
            clone.setAttribute(store_cjs_namespaceObject.isRefineModalFacet, '');
            clone.isCollapsed = -1 === this.collapseFacetsAfter ? false : i + 1 > this.collapseFacetsAfter;
            return clone;
        });
    }
    addFacetColumnStyling(el) {
        el.style.display = 'flex';
        el.style.flexDirection = 'column';
        el.style.gap = 'var(--atomic-refine-modal-facet-margin, 20px)';
    }
    renderFilters() {
        const hasFacetElements = this.bindings.store.getFacetElements().length > 0;
        if (!hasFacetElements) return external_lit_namespaceObject.nothing;
        const { i18n } = this.bindings;
        return (0, filters_cjs_namespaceObject.renderRefineModalFiltersSection)({
            props: {
                i18n,
                withFacets: hasFacetElements,
                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-results',
                host: this,
                isOpen: this.isOpen,
                onClose: ()=>{
                    this.isOpen = false;
                },
                title: this.bindings.i18n.t('filters'),
                numberOfItems: this.querySummaryState.total,
                openButton: this.openButton,
                boundary: 'element',
                scope: this.bindings.interfaceElement
            }
        })((0, body_cjs_namespaceObject.renderRefineModalBody)(this.bindings.i18n)((0, external_lit_namespaceObject.html)`${this.renderFilters()}`))}`;
    }
    constructor(...args){
        super(...args), this.isOpen = false, this.collapseFacetsAfter = 0;
    }
}
AtomicIpxRefineModal.styles = [
    (0, external_lit_namespaceObject.css)`
      @reference '../../../utils/tailwind.global.tw.css';

      :host::part(container) {
        border-radius: 0.25rem;
        max-height: calc(100vh - 4.25rem);
      }
    `
];
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Bindings ? Object : Bindings)
], AtomicIpxRefineModal.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicIpxRefineModal.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)
], AtomicIpxRefineModal.prototype, "openButton", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter,
        reflect: true,
        attribute: 'is-open'
    })
], AtomicIpxRefineModal.prototype, "isOpen", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'collapse-facets-after'
    })
], AtomicIpxRefineModal.prototype, "collapseFacetsAfter", 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)
], AtomicIpxRefineModal.prototype, "breadcrumbManagerState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('querySummary'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof QuerySummaryState ? Object : QuerySummaryState)
], AtomicIpxRefineModal.prototype, "querySummaryState", 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)
], AtomicIpxRefineModal.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)
], AtomicIpxRefineModal.prototype, "render", null);
AtomicIpxRefineModal = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-ipx-refine-modal'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicIpxRefineModal);
exports.AtomicIpxRefineModal = __webpack_exports__.AtomicIpxRefineModal;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicIpxRefineModal"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
