"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__, {
    AtomicSegmentedFacet: ()=>AtomicSegmentedFacet
});
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 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_values_group_cjs_namespaceObject = require("../../common/facets/facet-values-group/facet-values-group.cjs");
const facet_segmented_value_cjs_namespaceObject = require("../facets/facet-segmented-value/facet-segmented-value.cjs");
const facet_segmented_value_tw_css_cjs_namespaceObject = require("../facets/facet-segmented-value/facet-segmented-value.tw.css.cjs");
var facet_segmented_value_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(facet_segmented_value_tw_css_cjs_namespaceObject);
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 field_utils_cjs_namespaceObject = require("../../../utils/field-utils.cjs");
const props_utils_cjs_namespaceObject = require("../../../utils/props-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 AtomicSegmentedFacet extends external_lit_namespaceObject.LitElement {
    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.facet = (0, headless_namespaceObject.buildFacet)(this.bindings.engine, {
            options: this.facetOptions
        });
        this.facetId = this.facet.state.facetId;
        this.dependenciesManager = (0, headless_namespaceObject.buildFacetConditionsManager)(this.bindings.engine, {
            facetId: this.facetId,
            conditions: (0, depends_on_cjs_namespaceObject.parseDependsOn)(this.dependsOn)
        });
    }
    render() {
        if (this.searchStatusState.hasError || !this.facetState.enabled) return (0, external_lit_namespaceObject.html)``;
        if (!this.searchStatusState.firstSearchExecuted) return (0, external_lit_namespaceObject.html)`
        <div
          part="placeholder"
          aria-hidden="true"
          class="bg-neutral h-8 w-48 animate-pulse rounded"
        ></div>
      `;
        if (!this.facetState.values.length) return (0, external_lit_namespaceObject.html)``;
        return (0, external_lit_namespaceObject.html)`
      <div
        part="segmented-container"
        class="mr-2 flex h-10 items-center whitespace-nowrap"
      >
        ${this.renderLabel()} ${this.renderValues()}
      </div>
    `;
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        if (!this.isConnected) this.dependenciesManager?.stopWatching();
    }
    renderValuesContainer(children) {
        const classes = 'box-container flex h-10';
        return (0, facet_values_group_cjs_namespaceObject.renderFacetValuesGroup)({
            props: {
                i18n: this.bindings.i18n,
                label: this.label
            }
        })((0, external_lit_namespaceObject.html)`
      <ul class=${classes} part="values">
        ${children}
      </ul>
    `);
    }
    renderValue(facetValue, onClick) {
        const displayValue = (0, field_utils_cjs_namespaceObject.getFieldValueCaption)(this.field, facetValue.value, this.bindings.i18n);
        const isSelected = 'idle' !== facetValue.state;
        return (0, facet_segmented_value_cjs_namespaceObject.renderFacetSegmentedValue)({
            props: {
                displayValue,
                numberOfResults: facetValue.numberOfResults,
                isSelected,
                i18n: this.bindings.i18n,
                onClick,
                searchQuery: this.facetState.facetSearch.query
            }
        });
    }
    renderValues() {
        return this.renderValuesContainer(this.facetState.values.map((value)=>this.renderValue(value, ()=>this.facet.toggleSingleSelect(value))));
    }
    renderLabel() {
        return (0, when_js_namespaceObject.when)(this.label, ()=>(0, external_lit_namespaceObject.html)` <b class="mr-2" part="label"> ${this.label}: </b> `);
    }
    get facetOptions() {
        return {
            facetId: this.facetId,
            field: this.field,
            numberOfValues: this.numberOfValues,
            sortCriteria: this.sortCriteria,
            facetSearch: {
                numberOfValues: this.numberOfValues
            },
            filterFacetCount: this.filterFacetCount,
            injectionDepth: this.injectionDepth,
            hasBreadcrumbs: false,
            allowedValues: this.allowedValues.length ? this.allowedValues : void 0,
            customSort: this.customSort.length ? this.customSort : void 0,
            tabs: {
                included: this.tabsIncluded,
                excluded: this.tabsExcluded
            }
        };
    }
    constructor(...args){
        super(...args), this.tabsIncluded = [], this.tabsExcluded = [], this.filterFacetCount = true, this.injectionDepth = 1000, this.numberOfValues = 6, this.sortCriteria = 'automatic', this.allowedValues = [], this.customSort = [];
    }
}
AtomicSegmentedFacet.styles = [
    facet_common_tw_css_cjs_default(),
    facet_segmented_value_tw_css_cjs_default()
];
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Bindings ? Object : Bindings)
], AtomicSegmentedFacet.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof SearchStatus ? Object : SearchStatus)
], AtomicSegmentedFacet.prototype, "searchStatus", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof TabManager ? Object : TabManager)
], AtomicSegmentedFacet.prototype, "tabManager", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object
    }),
    _ts_metadata("design:type", "u" < typeof Facet ? Object : Facet)
], AtomicSegmentedFacet.prototype, "facet", 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)
], AtomicSegmentedFacet.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)
], AtomicSegmentedFacet.prototype, "tabManagerState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('facet'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof FacetState ? Object : FacetState)
], AtomicSegmentedFacet.prototype, "facetState", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicSegmentedFacet.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'facet-id'
    }),
    _ts_metadata("design:type", String)
], AtomicSegmentedFacet.prototype, "facetId", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true
    }),
    _ts_metadata("design:type", String)
], AtomicSegmentedFacet.prototype, "field", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true
    }),
    _ts_metadata("design:type", String)
], AtomicSegmentedFacet.prototype, "label", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Array,
        attribute: 'tabs-included',
        converter: array_converter_cjs_namespaceObject.arrayConverter,
        reflect: true
    }),
    _ts_metadata("design:type", Array)
], AtomicSegmentedFacet.prototype, "tabsIncluded", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Array,
        attribute: 'tabs-excluded',
        converter: array_converter_cjs_namespaceObject.arrayConverter,
        reflect: true
    }),
    _ts_metadata("design:type", Array)
], AtomicSegmentedFacet.prototype, "tabsExcluded", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter,
        attribute: 'filter-facet-count',
        reflect: true
    })
], AtomicSegmentedFacet.prototype, "filterFacetCount", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        attribute: 'injection-depth'
    })
], AtomicSegmentedFacet.prototype, "injectionDepth", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        type: Number,
        attribute: 'number-of-values'
    })
], AtomicSegmentedFacet.prototype, "numberOfValues", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'sort-criteria'
    }),
    _ts_metadata("design:type", "u" < typeof FacetSortCriterion ? Object : FacetSortCriterion)
], AtomicSegmentedFacet.prototype, "sortCriteria", void 0);
_ts_decorate([
    (0, props_utils_cjs_namespaceObject.mapProperty)({
        attributePrefix: 'depends-on'
    }),
    _ts_metadata("design:type", "u" < typeof Record ? Object : Record)
], AtomicSegmentedFacet.prototype, "dependsOn", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Array,
        attribute: 'allowed-values',
        converter: array_converter_cjs_namespaceObject.arrayConverter,
        reflect: true
    }),
    _ts_metadata("design:type", Array)
], AtomicSegmentedFacet.prototype, "allowedValues", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Array,
        attribute: 'custom-sort',
        converter: array_converter_cjs_namespaceObject.arrayConverter,
        reflect: true
    }),
    _ts_metadata("design:type", Array)
], AtomicSegmentedFacet.prototype, "customSort", 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)
], AtomicSegmentedFacet.prototype, "render", null);
AtomicSegmentedFacet = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-segmented-facet'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicSegmentedFacet);
exports.AtomicSegmentedFacet = __webpack_exports__.AtomicSegmentedFacet;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicSegmentedFacet"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
