"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__, {
    AtomicInsightFacet: ()=>AtomicInsightFacet
});
const bueno_namespaceObject = require("@coveo/bueno");
const insight_namespaceObject = require("@coveo/headless/insight");
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_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_search_aria_live_cjs_namespaceObject = require("../../common/facets/facet-search/facet-search-aria-live.cjs");
const facet_show_more_less_cjs_namespaceObject = require("../../common/facets/facet-show-more-less/facet-show-more-less.cjs");
const facet_value_cjs_namespaceObject = require("../../common/facets/facet-value/facet-value.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 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");
require("../../common/atomic-facet-placeholder/atomic-facet-placeholder.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_value_box_tw_css_cjs_namespaceObject = require("../../common/facets/facet-value-box/facet-value-box.tw.css.cjs");
var facet_value_box_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(facet_value_box_tw_css_cjs_namespaceObject);
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_exclude_tw_css_cjs_namespaceObject = require("../../common/facets/facet-value-exclude/facet-value-exclude.tw.css.cjs");
var facet_value_exclude_tw_css_cjs_default = /*#__PURE__*/ __webpack_require__.n(facet_value_exclude_tw_css_cjs_namespaceObject);
const validate_props_controller_cjs_namespaceObject = require("../../common/validate-props-controller/validate-props-controller.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 AtomicInsightFacet extends external_lit_namespaceObject.LitElement {
    initialize() {
        const options = {
            facetId: this.facetId,
            field: this.field,
            numberOfValues: this.numberOfValues,
            sortCriteria: this.sortCriteria,
            facetSearch: {
                numberOfValues: this.numberOfValues
            },
            filterFacetCount: this.filterFacetCount,
            injectionDepth: this.injectionDepth
        };
        this.facet = (0, insight_namespaceObject.buildFacet)(this.bindings.engine, {
            options
        });
        this.facetId = this.facet.state.facetId;
        this.searchStatus = (0, insight_namespaceObject.buildSearchStatus)(this.bindings.engine);
        this.initAriaLive();
        this.initConditionManager();
        this.initPopover();
        this.registerFacet();
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        if (!this.isConnected) this.facetConditionsManager?.stopWatching();
    }
    get focusTargets() {
        if (!this.showLessFocus) this.showLessFocus = new accessibility_utils_cjs_namespaceObject.FocusTargetController(this, this.bindings);
        if (!this.showMoreFocus) this.showMoreFocus = new accessibility_utils_cjs_namespaceObject.FocusTargetController(this, this.bindings);
        if (!this.headerFocus) this.headerFocus = new accessibility_utils_cjs_namespaceObject.FocusTargetController(this, this.bindings);
        return {
            showLess: this.showLessFocus,
            showMore: this.showMoreFocus,
            header: this.headerFocus
        };
    }
    shouldRenderFacet() {
        return this.facetState.enabled && !this.searchStatusState.hasError && (!this.searchStatusState.firstSearchExecuted || this.facetState.values.length > 0);
    }
    render() {
        return (0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)(this.shouldRenderFacet(), ()=>this.searchStatusState.firstSearchExecuted ? (0, facet_container_cjs_namespaceObject.renderFacetContainer)()((0, external_lit_namespaceObject.html)`
            ${this.renderFacetHeader()} ${this.renderBody()}
          `) : (0, external_lit_namespaceObject.html)`<atomic-facet-placeholder
            value-count="${this.numberOfValues}"
            ?is-collapsed="${this.isCollapsed}"
          ></atomic-facet-placeholder>`)}`;
    }
    renderFacetHeader() {
        return (0, facet_header_cjs_namespaceObject.renderFacetHeader)({
            props: {
                i18n: this.bindings.i18n,
                label: this.label,
                onClearFilters: ()=>{
                    this.focusTargets.header.focusAfterSearch();
                    this.facet.deselectAll();
                },
                numberOfActiveValues: this.activeValues.length,
                isCollapsed: this.isCollapsed,
                headingLevel: this.headingLevel,
                onToggleCollapse: ()=>{
                    this.isCollapsed = !this.isCollapsed;
                },
                headerRef: (el)=>this.focusTargets.header.setTarget(el)
            }
        });
    }
    renderBody() {
        if (this.isCollapsed) return external_lit_namespaceObject.nothing;
        return (0, external_lit_namespaceObject.html)`${this.renderValues()} ${this.renderShowMoreLess()}`;
    }
    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 ${'box' === this.displayValuesAs ? 'box-container' : ''}"
      part="values"
    >
      ${children}
    </ul>`);
    }
    renderValues() {
        const values = this.facet.state.values.map((value, i)=>{
            const shouldFocusOnShowLessAfterInteraction = 0 === i;
            const shouldFocusOnShowMoreAfterInteraction = i === ('automatic' === this.sortCriteria ? 0 : this.facetState.values.length - 1);
            return (0, facet_value_cjs_namespaceObject.renderFacetValue)({
                props: {
                    ...this.facetValueProps,
                    facetCount: value.numberOfResults,
                    onExclude: ()=>this.facet.toggleExclude(value),
                    onSelect: ()=>'link' === this.displayValuesAs ? this.facet.toggleSingleSelect(value) : this.facet.toggleSelect(value),
                    facetValue: value.value,
                    facetState: value.state,
                    setRef: (btn)=>{
                        if (shouldFocusOnShowLessAfterInteraction) this.showLessFocus?.setTarget(btn);
                        if (shouldFocusOnShowMoreAfterInteraction) this.showMoreFocus?.setTarget(btn);
                    }
                }
            });
        });
        return this.renderValuesContainer(values);
    }
    renderShowMoreLess() {
        return (0, facet_show_more_less_cjs_namespaceObject.renderFacetShowMoreLess)({
            props: {
                label: this.label,
                i18n: this.bindings.i18n,
                onShowMore: ()=>{
                    this.focusTargets.showMore.focusAfterSearch();
                    this.facet.showMoreValues();
                },
                onShowLess: ()=>{
                    this.focusTargets.showLess.focusAfterSearch();
                    this.facet.showLessValues();
                },
                canShowMoreValues: this.facet.state.canShowMoreValues,
                canShowLessValues: this.facet.state.canShowLessValues
            }
        });
    }
    get activeValues() {
        return this.facet.state.values.filter(({ state })=>'idle' !== state);
    }
    get facetValueProps() {
        return {
            facetSearchQuery: this.facetState.facetSearch.query,
            displayValuesAs: this.displayValuesAs,
            enableExclusion: this.enableExclusion,
            field: this.field,
            i18n: this.bindings.i18n
        };
    }
    initAriaLive() {
        this.facetSearchAriaLiveController = new accessibility_utils_cjs_namespaceObject.AriaLiveRegionController(this, 'facet-search');
        (0, facet_search_aria_live_cjs_namespaceObject.announceFacetSearchResultsWithAriaLive)(this.facet, this.label, (msg)=>{
            this.facetSearchAriaLiveController.message = msg;
        }, this.bindings.i18n);
    }
    initConditionManager() {
        this.facetConditionsManager = (0, insight_namespaceObject.buildFacetConditionsManager)(this.bindings.engine, {
            facetId: this.facetId,
            conditions: (0, depends_on_cjs_namespaceObject.parseDependsOn)(this.dependsOn)
        });
    }
    initPopover() {
        (0, popover_type_cjs_namespaceObject.initializePopover)(this, {
            ...this.facetInfo,
            hasValues: ()=>!!this.facet.state.values.length,
            numberOfActiveValues: ()=>this.activeValues.length
        });
    }
    get isHidden() {
        return !this.facet.state.enabled || !this.facet.state.values.length;
    }
    get facetInfo() {
        return {
            label: ()=>this.bindings.i18n.t(this.label),
            facetId: this.facetId,
            element: this,
            isHidden: ()=>this.isHidden
        };
    }
    registerFacet() {
        this.bindings.store.registerFacet('facets', this.facetInfo);
    }
    constructor(){
        super(), this.label = 'no-label', this.numberOfValues = 8, this.sortCriteria = 'automatic', this.displayValuesAs = 'checkbox', this.isCollapsed = false, this.headingLevel = 0, this.filterFacetCount = true, this.injectionDepth = 1000, this.enableExclusion = false, this.dependsOn = {};
        new validate_props_controller_cjs_namespaceObject.ValidatePropsController(this, ()=>({
                field: this.field,
                numberOfValues: this.numberOfValues,
                injectionDepth: this.injectionDepth
            }), AtomicInsightFacet.propsSchema, false);
    }
}
AtomicInsightFacet.propsSchema = new bueno_namespaceObject.Schema({
    field: new bueno_namespaceObject.StringValue({
        required: true,
        emptyAllowed: false
    }),
    numberOfValues: new bueno_namespaceObject.NumberValue({
        min: 1
    }),
    injectionDepth: new bueno_namespaceObject.NumberValue({
        min: 0
    })
});
AtomicInsightFacet.styles = [
    facet_common_tw_css_cjs_default(),
    facet_value_box_tw_css_cjs_default(),
    facet_value_checkbox_tw_css_cjs_default(),
    facet_value_exclude_tw_css_cjs_default()
];
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        reflect: true
    })
], AtomicInsightFacet.prototype, "label", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        reflect: true
    }),
    _ts_metadata("design:type", String)
], AtomicInsightFacet.prototype, "field", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'number-of-values'
    })
], AtomicInsightFacet.prototype, "numberOfValues", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        reflect: true,
        attribute: 'sort-criteria'
    }),
    _ts_metadata("design:type", "u" < typeof InsightFacetSortCriterion ? Object : InsightFacetSortCriterion)
], AtomicInsightFacet.prototype, "sortCriteria", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        reflect: true,
        attribute: 'display-values-as'
    }),
    _ts_metadata("design:type", String)
], AtomicInsightFacet.prototype, "displayValuesAs", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        reflect: true,
        attribute: 'is-collapsed'
    })
], AtomicInsightFacet.prototype, "isCollapsed", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'heading-level'
    })
], AtomicInsightFacet.prototype, "headingLevel", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        reflect: true,
        attribute: 'filter-facet-count'
    })
], AtomicInsightFacet.prototype, "filterFacetCount", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        attribute: 'injection-depth'
    })
], AtomicInsightFacet.prototype, "injectionDepth", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        reflect: true,
        attribute: 'enable-exclusion'
    })
], AtomicInsightFacet.prototype, "enableExclusion", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        reflect: true,
        attribute: 'facet-id'
    }),
    _ts_metadata("design:type", String)
], AtomicInsightFacet.prototype, "facetId", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof InsightBindings ? Object : InsightBindings)
], AtomicInsightFacet.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicInsightFacet.prototype, "error", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('facet'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof InsightFacetState ? Object : InsightFacetState)
], AtomicInsightFacet.prototype, "facetState", void 0);
_ts_decorate([
    (0, bind_state_cjs_namespaceObject.bindStateToController)('searchStatus'),
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof InsightSearchStatusState ? Object : InsightSearchStatusState)
], AtomicInsightFacet.prototype, "searchStatusState", 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)
], AtomicInsightFacet.prototype, "render", null);
AtomicInsightFacet = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-insight-facet'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles,
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicInsightFacet);
exports.AtomicInsightFacet = __webpack_exports__.AtomicInsightFacet;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicInsightFacet"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
