"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__, {
    AtomicRatingFacet: ()=>AtomicRatingFacet
});
const bueno_namespaceObject = require("@coveo/bueno");
const headless_namespaceObject = require("@coveo/headless");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const when_js_namespaceObject = require("lit/directives/when.js");
const atomic_rating_tw_css_cjs_namespaceObject = require("../../common/atomic-rating/atomic-rating.tw.css.cjs");
var atomic_rating_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(atomic_rating_tw_css_cjs_namespaceObject);
const rating_cjs_namespaceObject = require("../../common/atomic-rating/rating.cjs");
const depends_on_cjs_namespaceObject = require("../../common/facets/depends-on.cjs");
const facet_common_tw_css_cjs_namespaceObject = require("../../common/facets/facet-common.tw.css.cjs");
var facet_common_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(facet_common_tw_css_cjs_namespaceObject);
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 facet_placeholder_cjs_namespaceObject = require("../../common/facets/facet-placeholder/facet-placeholder.cjs");
const facet_value_checkbox_cjs_namespaceObject = require("../../common/facets/facet-value-checkbox/facet-value-checkbox.cjs");
const facet_value_checkbox_tw_css_cjs_namespaceObject = require("../../common/facets/facet-value-checkbox/facet-value-checkbox.tw.css.cjs");
var facet_value_checkbox_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(facet_value_checkbox_tw_css_cjs_namespaceObject);
const facet_value_link_cjs_namespaceObject = require("../../common/facets/facet-value-link/facet-value-link.cjs");
const facet_values_group_cjs_namespaceObject = require("../../common/facets/facet-values-group/facet-values-group.cjs");
const popover_type_cjs_namespaceObject = require("../../common/facets/popover/popover-type.cjs");
const validate_props_controller_cjs_namespaceObject = require("../../common/validate-props-controller/validate-props-controller.cjs");
const array_converter_cjs_namespaceObject = require("../../../converters/array-converter.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 with_tailwind_styles_cjs_namespaceObject = require("../../../decorators/with-tailwind-styles.cjs");
const accessibility_utils_cjs_namespaceObject = require("../../../utils/accessibility-utils.cjs");
const props_utils_cjs_namespaceObject = require("../../../utils/props-utils.cjs");
const star_cjs_namespaceObject = require("../../../images/star.cjs");
var star_cjs_default = /*#__PURE__*/ __webpack_require__.n(star_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 AtomicRatingFacet extends external_lit_namespaceObject.LitElement {
    get focusTarget() {
        if (!this.headerFocus) this.headerFocus = new accessibility_utils_cjs_namespaceObject.FocusTargetController(this, this.bindings);
        return this.headerFocus;
    }
    connectedCallback() {
        super.connectedCallback();
        if (void 0 === this.maxValueInIndex) this.maxValueInIndex = this.numberOfIntervals;
    }
    get _filterFacetCount() {
        return this.filterFacetCount ?? true;
    }
    initialize() {
        if ([
            ...this.tabsIncluded
        ].length > 0 && [
            ...this.tabsExcluded
        ].length > 0) console.warn('Values for both "tabs-included" and "tabs-excluded" have been provided. This is could lead to unexpected behaviors.');
        this.searchStatus = (0, headless_namespaceObject.buildSearchStatus)(this.bindings.engine);
        this.tabManager = (0, headless_namespaceObject.buildTabManager)(this.bindings.engine);
        this.initializeFacet();
        this.initializeDependenciesManager();
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        if (!this.isConnected) this.dependenciesManager?.stopWatching();
    }
    initializeFacet() {
        const options = {
            facetId: this.facetId,
            field: this.field,
            numberOfValues: this.numberOfIntervals,
            currentValues: this.generateCurrentValues(),
            sortCriteria: 'descending',
            generateAutomaticRanges: false,
            filterFacetCount: this._filterFacetCount,
            injectionDepth: this.injectionDepth,
            tabs: {
                included: [
                    ...this.tabsIncluded
                ],
                excluded: [
                    ...this.tabsExcluded
                ]
            }
        };
        this.facet = (0, headless_namespaceObject.buildNumericFacet)(this.bindings.engine, {
            options
        });
        this.facetId = this.facet.state.facetId;
        const facetInfo = {
            label: ()=>this.bindings.i18n.t(this.label),
            facetId: this.facetId,
            element: this,
            isHidden: ()=>this.isHidden
        };
        this.bindings.store.registerFacet('numericFacets', {
            ...facetInfo,
            format: (value)=>this.formatFacetValue(value),
            content: (value)=>this.ratingContent(value)
        });
        (0, popover_type_cjs_namespaceObject.initializePopover)(this, {
            ...facetInfo,
            hasValues: ()=>!!this.valuesToRender.length,
            numberOfActiveValues: ()=>this.numberOfSelectedValues
        });
    }
    get isHidden() {
        return this.searchStatusState.hasError || !this.facet.state.enabled || !this.valuesToRender.length;
    }
    get scaleFactor() {
        return (this.maxValueInIndex ?? this.numberOfIntervals) / this.numberOfIntervals;
    }
    get numberOfSelectedValues() {
        return this.facetState.values.filter(({ state })=>'selected' === state).length;
    }
    initializeDependenciesManager() {
        this.dependenciesManager = (0, headless_namespaceObject.buildFacetConditionsManager)(this.bindings.engine, {
            facetId: this.facetId,
            conditions: (0, depends_on_cjs_namespaceObject.parseDependsOn)(this.dependsOn || {})
        });
    }
    generateCurrentValues() {
        const currentValues = [];
        for(let i = this.minValueInIndex; i <= this.numberOfIntervals; i++)currentValues.push((0, headless_namespaceObject.buildNumericRange)({
            start: Math.round(i * this.scaleFactor * 100) / 100,
            end: Math.round((i + 1) * this.scaleFactor * 100) / 100,
            endInclusive: false
        }));
        return currentValues;
    }
    formatFacetValue(facetValue) {
        const maxValue = this.maxValueInIndex ?? this.numberOfIntervals;
        if (facetValue.start === maxValue) return this.bindings.i18n.t('stars-only', {
            count: facetValue.start
        });
        return this.bindings.i18n.t('stars', {
            count: facetValue.start,
            max: maxValue
        });
    }
    ratingContent(facetValue) {
        return (0, rating_cjs_namespaceObject.renderRating)({
            props: {
                i18n: this.bindings.i18n,
                numberOfTotalIcons: this.maxValueInIndex ?? this.numberOfIntervals,
                numberOfActiveIcons: facetValue.start,
                icon: this.icon
            }
        });
    }
    renderHeader() {
        return (0, facet_header_cjs_namespaceObject.renderFacetHeader)({
            props: {
                i18n: this.bindings.i18n,
                label: this.label,
                onClearFilters: ()=>{
                    this.focusTarget.focusAfterSearch();
                    this.facet.deselectAll();
                },
                numberOfActiveValues: this.numberOfSelectedValues,
                isCollapsed: this.isCollapsed,
                headingLevel: this.headingLevel,
                onToggleCollapse: ()=>{
                    this.isCollapsed = !this.isCollapsed;
                },
                headerRef: (el)=>this.focusTarget.setTarget(el)
            }
        });
    }
    renderValue(facetValue, onClick) {
        const displayValue = this.formatFacetValue(facetValue);
        const isSelected = 'selected' === facetValue.state;
        const shouldBeDimmed = this.facetState.hasActiveValues && !isSelected;
        switch(this.displayValuesAs){
            case 'checkbox':
                return (0, facet_value_checkbox_cjs_namespaceObject.renderFacetValueCheckbox)({
                    props: {
                        displayValue,
                        numberOfResults: facetValue.numberOfResults,
                        isSelected,
                        i18n: this.bindings.i18n,
                        onClick
                    }
                })(this.ratingContent(facetValue));
            case 'link':
                return (0, facet_value_link_cjs_namespaceObject.renderFacetValueLink)({
                    props: {
                        displayValue,
                        numberOfResults: facetValue.numberOfResults,
                        isSelected,
                        i18n: this.bindings.i18n,
                        onClick,
                        class: shouldBeDimmed ? 'opacity-80' : void 0
                    }
                })(this.ratingContent(facetValue));
        }
    }
    renderValuesContainer(children) {
        return (0, facet_values_group_cjs_namespaceObject.renderFacetValuesGroup)({
            props: {
                i18n: this.bindings.i18n,
                label: this.label
            }
        })((0, external_lit_namespaceObject.html)`<ul class="mt-3" part="values">
        ${children}
      </ul>`);
    }
    renderValues() {
        return this.renderValuesContainer(this.valuesToRender.map((value)=>this.renderValue(value, ()=>'link' === this.displayValuesAs ? this.facet.toggleSingleSelect(value) : this.facet.toggleSelect(value))));
    }
    get valuesToRender() {
        return this.facet.state.values.filter((value)=>value.numberOfResults || 'idle' !== value.state);
    }
    render() {
        if (this.searchStatusState.hasError || !this.facet.state.enabled) return external_lit_namespaceObject.nothing;
        if (!this.searchStatusState.firstSearchExecuted) return (0, external_lit_namespaceObject.html)`${(0, facet_placeholder_cjs_namespaceObject.renderFacetPlaceholder)({
            props: {
                numberOfValues: this.numberOfIntervals,
                isCollapsed: this.isCollapsed
            }
        })}`;
        if (!this.valuesToRender.length) return external_lit_namespaceObject.nothing;
        return (0, facet_container_cjs_namespaceObject.renderFacetContainer)()((0, external_lit_namespaceObject.html)`
      ${this.renderHeader()}
      ${(0, when_js_namespaceObject.when)(!this.isCollapsed, ()=>this.renderValues())}
    `);
    }
    constructor(){
        super(), this.label = 'no-label', this.numberOfIntervals = 5, this.tabsIncluded = [], this.tabsExcluded = [], this.minValueInIndex = 1, this.displayValuesAs = 'checkbox', this.icon = star_cjs_default(), this.isCollapsed = false, this.headingLevel = 0, this.injectionDepth = 1000;
        new validate_props_controller_cjs_namespaceObject.ValidatePropsController(this, ()=>({
                field: this.field,
                numberOfIntervals: this.numberOfIntervals,
                maxValueInIndex: this.maxValueInIndex,
                minValueInIndex: this.minValueInIndex,
                displayValuesAs: this.displayValuesAs,
                injectionDepth: this.injectionDepth,
                dependsOn: this.dependsOn,
                headingLevel: this.headingLevel
            }), AtomicRatingFacet.propsSchema, false);
    }
}
AtomicRatingFacet.propsSchema = new bueno_namespaceObject.Schema({
    field: new bueno_namespaceObject.StringValue({
        required: true,
        emptyAllowed: false
    }),
    numberOfIntervals: new bueno_namespaceObject.NumberValue({
        min: 1
    }),
    maxValueInIndex: new bueno_namespaceObject.NumberValue({
        min: 0,
        required: false
    }),
    minValueInIndex: new bueno_namespaceObject.NumberValue({
        min: 0
    }),
    displayValuesAs: new bueno_namespaceObject.StringValue({
        constrainTo: [
            'checkbox',
            'link'
        ]
    }),
    injectionDepth: new bueno_namespaceObject.NumberValue({
        min: 0,
        required: false
    }),
    dependsOn: new bueno_namespaceObject.RecordValue({
        options: {
            required: false
        }
    }),
    headingLevel: new bueno_namespaceObject.NumberValue({
        min: 0,
        max: 6,
        required: false
    })
});
AtomicRatingFacet.styles = [
    facet_common_tw_css_cjs_default(),
    facet_value_checkbox_tw_css_cjs_default(),
    atomic_rating_tw_css_cjs_default()
];
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Bindings ? Object : Bindings)
], AtomicRatingFacet.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicRatingFacet.prototype, "error", 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)
], AtomicRatingFacet.prototype, "facetState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('searchStatus'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof SearchStatusState ? Object : SearchStatusState)
], AtomicRatingFacet.prototype, "searchStatusState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('tabManager'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof TabManagerState ? Object : TabManagerState)
], AtomicRatingFacet.prototype, "tabManagerState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'facet-id',
        type: String
    }),
    _ts_metadata("design:type", String)
], AtomicRatingFacet.prototype, "facetId", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: String
    })
], AtomicRatingFacet.prototype, "label", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: String
    }),
    _ts_metadata("design:type", String)
], AtomicRatingFacet.prototype, "field", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'number-of-intervals',
        type: Number
    })
], AtomicRatingFacet.prototype, "numberOfIntervals", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'tabs-included',
        type: Array,
        converter: array_converter_cjs_namespaceObject.arrayConverter
    }),
    _ts_metadata("design:type", Array)
], AtomicRatingFacet.prototype, "tabsIncluded", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'tabs-excluded',
        converter: array_converter_cjs_namespaceObject.arrayConverter,
        type: Array
    }),
    _ts_metadata("design:type", Array)
], AtomicRatingFacet.prototype, "tabsExcluded", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'max-value-in-index',
        type: Number
    }),
    _ts_metadata("design:type", Number)
], AtomicRatingFacet.prototype, "maxValueInIndex", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'min-value-in-index',
        type: Number
    })
], AtomicRatingFacet.prototype, "minValueInIndex", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'display-values-as',
        type: String
    }),
    _ts_metadata("design:type", String)
], AtomicRatingFacet.prototype, "displayValuesAs", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: String
    })
], AtomicRatingFacet.prototype, "icon", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'is-collapsed',
        type: Boolean,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter
    })
], AtomicRatingFacet.prototype, "isCollapsed", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'heading-level',
        type: Number
    })
], AtomicRatingFacet.prototype, "headingLevel", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'filter-facet-count',
        type: Boolean,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter
    }),
    _ts_metadata("design:type", Boolean)
], AtomicRatingFacet.prototype, "filterFacetCount", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'injection-depth',
        type: Number
    })
], AtomicRatingFacet.prototype, "injectionDepth", void 0);
_ts_decorate([
    (0, props_utils_cjs_namespaceObject.mapProperty)({
        attributePrefix: 'depends-on'
    }),
    _ts_metadata("design:type", "u" < typeof Record ? Object : Record)
], AtomicRatingFacet.prototype, "dependsOn", 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)
], AtomicRatingFacet.prototype, "render", null);
AtomicRatingFacet = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-rating-facet'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles,
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicRatingFacet);
exports.AtomicRatingFacet = __webpack_exports__.AtomicRatingFacet;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicRatingFacet"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
