"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__, {
    AtomicInsightRefineModal: ()=>AtomicInsightRefineModal
});
const insight_namespaceObject = require("@coveo/headless/insight");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const button_cjs_namespaceObject = require("../../common/button.cjs");
const cloned_facet_elements_cjs_namespaceObject = require("../../common/refine-modal/cloned-facet-elements.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 dom_utils_cjs_namespaceObject = require("../../../utils/dom-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 AtomicInsightRefineModal extends external_lit_namespaceObject.LitElement {
    initialize() {
        this.querySummary = (0, insight_namespaceObject.buildQuerySummary)(this.bindings.engine);
        this.breadcrumbManager = (0, insight_namespaceObject.buildBreadcrumbManager)(this.bindings.engine);
    }
    connectedCallback() {
        super.connectedCallback();
        this.style.display = '';
        this.shadowRoot?.adoptedStyleSheets.push(this.backdropStyleSheet);
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        if (this.animationFrameId) window.cancelAnimationFrame(this.animationFrameId);
    }
    willUpdate(changedProperties) {
        if (changedProperties.has('interfaceDimensions')) this.updateBackdropStyles();
    }
    watchEnabled() {
        if (this.isOpen) {
            if (!this.querySelector('div[slot="facets"]')) this.appendChild((0, cloned_facet_elements_cjs_namespaceObject.getClonedFacetElements)(this.bindings.store.getFacetElements(), 0, this.bindings.interfaceElement));
            this.onAnimationFrame();
        }
    }
    onAnimationFrame() {
        if (!this.isOpen) return;
        if (this.dimensionChanged()) this.updateDimensions();
        this.animationFrameId = window.requestAnimationFrame(()=>this.onAnimationFrame());
    }
    dimensionChanged() {
        if (!this.interfaceDimensions) return true;
        return !(0, dom_utils_cjs_namespaceObject.rectEquals)(this.interfaceDimensions, this.bindings.interfaceElement.getBoundingClientRect());
    }
    updateDimensions() {
        this.interfaceDimensions = this.bindings.interfaceElement.getBoundingClientRect();
        this.updateBackdropStyles();
    }
    updateBackdropStyles() {
        if (this.interfaceDimensions) this.backdropStyleSheet.replaceSync(`
        atomic-modal::part(backdrop) {
          top: ${this.interfaceDimensions.top}px;
          left: ${this.interfaceDimensions.left}px;
          width: ${this.interfaceDimensions.width}px;
          height: ${this.interfaceDimensions.height}px;
        }
      `);
        else this.backdropStyleSheet.replaceSync('');
    }
    renderHeader() {
        if (!this.breadcrumbManagerState.hasBreadcrumbs) return external_lit_namespaceObject.nothing;
        return (0, external_lit_namespaceObject.html)`
      <div class="mb-3 flex w-full justify-between">
        ${(0, button_cjs_namespaceObject.renderButton)({
            props: {
                onClick: ()=>this.breadcrumbManager.deselectAll(),
                style: 'text-primary',
                text: this.bindings.i18n.t('clear-all-filters'),
                class: 'px-2 py-1'
            }
        })(external_lit_namespaceObject.nothing)}
      </div>
    `;
    }
    renderBody() {
        if (!this.bindings.store.getFacetElements().length) return external_lit_namespaceObject.nothing;
        return (0, external_lit_namespaceObject.html)`
      <aside
        slot="body"
        class="flex w-full flex-col"
        aria-label=${this.bindings.i18n.t('refine-modal-content')}
      >
        ${this.renderHeader()}
        <slot name="facets"></slot>
      </aside>
    `;
    }
    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,
                scope: this.bindings.interfaceElement
            }
        })(this.renderBody())}
    `;
    }
    constructor(...args){
        super(...args), this.isOpen = false, this.backdropStyleSheet = new CSSStyleSheet();
    }
}
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof InsightBindings ? Object : InsightBindings)
], AtomicInsightRefineModal.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicInsightRefineModal.prototype, "error", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('querySummary'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof InsightQuerySummaryState ? Object : InsightQuerySummaryState)
], AtomicInsightRefineModal.prototype, "querySummaryState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('breadcrumbManager'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof InsightBreadcrumbManagerState ? Object : InsightBreadcrumbManagerState)
], AtomicInsightRefineModal.prototype, "breadcrumbManagerState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof DOMRect ? Object : DOMRect)
], AtomicInsightRefineModal.prototype, "interfaceDimensions", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        attribute: 'open-button',
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof HTMLElement ? Object : HTMLElement)
], AtomicInsightRefineModal.prototype, "openButton", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter,
        reflect: true,
        attribute: 'is-open'
    })
], AtomicInsightRefineModal.prototype, "isOpen", 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)
], AtomicInsightRefineModal.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)
], AtomicInsightRefineModal.prototype, "render", null);
AtomicInsightRefineModal = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-insight-refine-modal'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicInsightRefineModal);
exports.AtomicInsightRefineModal = __webpack_exports__.AtomicInsightRefineModal;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicInsightRefineModal"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
