"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__, {
    AtomicCommerceNumericFacet: ()=>AtomicCommerceNumericFacet
});
const commerce_namespaceObject = require("@coveo/headless/commerce");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const when_js_namespaceObject = require("lit/directives/when.js");
const values_container_cjs_namespaceObject = require("../../common/facets/numeric-facet/values-container.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 error_guard_cjs_namespaceObject = require("../../../decorators/error-guard.cjs");
const with_tailwind_styles_cjs_namespaceObject = require("../../../decorators/with-tailwind-styles.cjs");
const accessibility_utils_cjs_namespaceObject = require("../../../utils/accessibility-utils.cjs");
const facet_common_cjs_namespaceObject = require("../../common/facets/facet-common.cjs");
const facet_container_cjs_namespaceObject = require("../../common/facets/facet-container/facet-container.cjs");
const facet_header_cjs_namespaceObject = require("../../common/facets/facet-header/facet-header.cjs");
const value_link_cjs_namespaceObject = require("../../common/facets/numeric-facet/value-link.cjs");
const format_common_cjs_namespaceObject = require("../../common/formats/format-common.cjs");
require("../atomic-commerce-facet-number-input/atomic-commerce-facet-number-input.cjs");
const bindings_cjs_namespaceObject = require("../../../decorators/bindings.cjs");
const numeric_facet_common_tw_css_cjs_namespaceObject = require("../../common/facets/numeric-facet-common.tw.css.cjs");
var numeric_facet_common_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(numeric_facet_common_tw_css_cjs_namespaceObject);
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 AtomicCommerceNumericFacet extends external_lit_namespaceObject.LitElement {
    initialize() {
        this.validateFacet();
        this.context = (0, commerce_namespaceObject.buildContext)(this.bindings.engine);
        this.ensureSubscribed();
    }
    disconnectedCallback() {
        this.unsubscribeFacetController?.();
        this.unsubscribeFacetController = void 0;
        super.disconnectedCallback();
    }
    updated(changedProps) {
        super.updated(changedProps);
        if (changedProps.has('facet')) this.validateFacet();
    }
    get formatter() {
        if ('ec_price' === this.field || 'ec_promo_price' === this.field) return (0, format_common_cjs_namespaceObject.defaultCurrencyFormatter)(this.contextState.currency);
        return format_common_cjs_namespaceObject.defaultNumberFormatter;
    }
    get focusTarget() {
        if (!this.headerFocus) this.headerFocus = new accessibility_utils_cjs_namespaceObject.FocusTargetController(this, this.bindings);
        return this.headerFocus;
    }
    get displayName() {
        return this.facetState.displayName || 'no-label';
    }
    get numberOfSelectedValues() {
        return this.facetState.values.filter(({ state })=>'selected' === state).length || 0;
    }
    get hasInputRange() {
        return !!this.facetState.manualRange;
    }
    get shouldRenderValues() {
        return !this.hasInputRange && !!this.valuesToRender.length;
    }
    get valuesToRender() {
        return this.facetState.values.filter((value)=>value.numberOfResults || 'idle' !== value.state) || [];
    }
    get shouldRenderInput() {
        const { firstRequestExecuted: firstSearchExecuted, hasError, isLoading, hasProducts: hasResults } = this.summaryState;
        return (0, facet_common_cjs_namespaceObject.shouldDisplayInputForFacetRange)({
            hasInputRange: this.hasInputRange,
            searchStatusState: {
                firstSearchExecuted,
                hasError,
                hasResults,
                isLoading
            },
            facetValues: this.facetState.values,
            hasInput: true
        });
    }
    get shouldRenderFacet() {
        return this.shouldRenderInput || this.shouldRenderValues;
    }
    ensureSubscribed() {
        if (this.unsubscribeFacetController) return;
        this.unsubscribeFacetController = this.facet?.subscribe(()=>{
            this.facetState = this.facet.state;
        });
    }
    renderValues() {
        return (0, values_container_cjs_namespaceObject.renderNumericFacetValuesGroup)({
            props: {
                i18n: this.bindings.i18n,
                label: this.displayName
            }
        })((0, external_lit_namespaceObject.html)`${this.valuesToRender.map((value)=>(0, value_link_cjs_namespaceObject.renderNumericFacetValue)({
                props: {
                    formatter: this.formatter,
                    displayValuesAs: 'checkbox',
                    facetValue: value,
                    field: this.facetState.field,
                    i18n: this.bindings.i18n,
                    logger: this.bindings.engine.logger,
                    manualRanges: [],
                    onClick: ()=>this.facet.toggleSelect(value)
                }
            }))} `);
    }
    onNumberInputApply(event) {
        const { detail: { start, end } } = event;
        this.facet.setRanges([
            {
                start,
                end,
                endInclusive: true,
                state: 'selected'
            }
        ]);
    }
    render() {
        const { firstRequestExecuted } = this.summaryState;
        return (0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)(!firstRequestExecuted || this.shouldRenderFacet, ()=>(0, facet_container_cjs_namespaceObject.renderFacetContainer)()((0, external_lit_namespaceObject.html)`${(0, facet_header_cjs_namespaceObject.renderFacetHeader)({
                props: {
                    i18n: this.bindings.i18n,
                    label: this.displayName,
                    numberOfActiveValues: this.numberOfSelectedValues,
                    isCollapsed: this.isCollapsed,
                    headingLevel: 0,
                    onToggleCollapse: ()=>{
                        this.isCollapsed = !this.isCollapsed;
                    },
                    onClearFilters: ()=>{
                        this.focusTarget.focusAfterSearch();
                        this.facet.deselectAll();
                    },
                    headerRef: (el)=>this.focusTarget.setTarget(el)
                }
            })}
        ${(0, when_js_namespaceObject.when)(!this.isCollapsed, ()=>(0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)(this.shouldRenderValues, ()=>this.renderValues())}
            ${(0, when_js_namespaceObject.when)(this.shouldRenderInput, ()=>(0, external_lit_namespaceObject.html)`<atomic-commerce-facet-number-input
                  label=${this.displayName}
                  .facet=${this.facet}
                  .range=${this.facetState.manualRange}
                  @atomic-number-input-apply=${this.onNumberInputApply}
                ></atomic-commerce-facet-number-input>`)}`)}`))}`;
    }
    validateFacet() {
        if (!this.facet) this.error = new Error('The "facet" property is required for <atomic-commerce-facet>.');
    }
    constructor(...args){
        super(...args), this.isCollapsed = false;
    }
}
AtomicCommerceNumericFacet.styles = numeric_facet_common_tw_css_cjs_default();
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof Summary ? Object : Summary)
], AtomicCommerceNumericFacet.prototype, "summary", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof NumericFacet ? Object : NumericFacet)
], AtomicCommerceNumericFacet.prototype, "facet", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        reflect: true,
        attribute: 'is-collapsed',
        converter: boolean_converter_cjs_namespaceObject.booleanConverter
    })
], AtomicCommerceNumericFacet.prototype, "isCollapsed", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true
    }),
    _ts_metadata("design:type", String)
], AtomicCommerceNumericFacet.prototype, "field", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof CommerceBindings ? Object : CommerceBindings)
], AtomicCommerceNumericFacet.prototype, "bindings", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('facet'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof NumericFacetState ? Object : NumericFacetState)
], AtomicCommerceNumericFacet.prototype, "facetState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('summary'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", Object)
], AtomicCommerceNumericFacet.prototype, "summaryState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('context'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof ContextState ? Object : ContextState)
], AtomicCommerceNumericFacet.prototype, "contextState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicCommerceNumericFacet.prototype, "error", 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)
], AtomicCommerceNumericFacet.prototype, "render", null);
AtomicCommerceNumericFacet = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-commerce-numeric-facet'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicCommerceNumericFacet);
exports.AtomicCommerceNumericFacet = __webpack_exports__.AtomicCommerceNumericFacet;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicCommerceNumericFacet"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
