"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__, {
    AtomicAutomaticFacet: ()=>AtomicAutomaticFacet
});
const bueno_namespaceObject = require("@coveo/bueno");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const when_js_namespaceObject = require("lit/directives/when.js");
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_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_label_highlight_cjs_namespaceObject = require("../../common/facets/facet-value-label-highlight/facet-value-label-highlight.cjs");
const facet_values_group_cjs_namespaceObject = require("../../common/facets/facet-values-group/facet-values-group.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 bindings_mixin_cjs_namespaceObject = require("../../../mixins/bindings-mixin.cjs");
const accessibility_utils_cjs_namespaceObject = require("../../../utils/accessibility-utils.cjs");
const field_utils_cjs_namespaceObject = require("../../../utils/field-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 AtomicAutomaticFacet extends (0, bindings_mixin_cjs_namespaceObject.InitializeBindingsMixin)(external_lit_namespaceObject.LitElement) {
    initialize() {}
    get focusTarget() {
        if (!this.headerFocus) this.headerFocus = new accessibility_utils_cjs_namespaceObject.FocusTargetController(this, this.bindings);
        return this.headerFocus;
    }
    get numberOfSelectedValues() {
        return this.facet.state.values.filter((value)=>this.isSelected(value)).length;
    }
    isSelected(value) {
        return 'selected' === value.state;
    }
    get label() {
        return (0, bueno_namespaceObject.isNullOrUndefined)(this.facet.state.label) ? this.facet.state.field : this.facet.state.label;
    }
    renderValue(facetValue, onClick) {
        const displayValue = (0, field_utils_cjs_namespaceObject.getFieldValueCaption)(this.facet.state.field, facetValue.value, this.bindings.i18n);
        return (0, facet_value_checkbox_cjs_namespaceObject.renderFacetValueCheckbox)({
            props: {
                displayValue,
                numberOfResults: facetValue.numberOfResults,
                isSelected: this.isSelected(facetValue),
                i18n: this.bindings.i18n,
                onClick
            }
        })((0, external_lit_namespaceObject.html)`${(0, facet_value_label_highlight_cjs_namespaceObject.renderFacetValueLabelHighlight)({
            props: {
                displayValue,
                isSelected: this.isSelected(facetValue)
            }
        })}`);
    }
    renderValuesContainer(children, query) {
        return (0, facet_values_group_cjs_namespaceObject.renderFacetValuesGroup)({
            props: {
                i18n: this.bindings.i18n,
                label: this.facet.state.label,
                query
            }
        })((0, external_lit_namespaceObject.html)`<ul class="mt-3" part="values">
        ${children}
      </ul>`);
    }
    renderValues() {
        return this.renderValuesContainer(this.facet.state.values.map((value)=>this.renderValue(value, ()=>this.facet.toggleSelect(value))));
    }
    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: 0,
                onToggleCollapse: ()=>{
                    this.isCollapsed = !this.isCollapsed;
                },
                headerRef: (el)=>this.focusTarget.setTarget(el)
            }
        });
    }
    render() {
        if (this.searchStatus.state.hasError) 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(...args){
        super(...args), this.isCollapsed = false;
    }
}
AtomicAutomaticFacet.styles = [
    facet_common_tw_css_cjs_default(),
    facet_value_checkbox_tw_css_cjs_default()
];
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Bindings ? Object : Bindings)
], AtomicAutomaticFacet.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicAutomaticFacet.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        reflect: true
    }),
    _ts_metadata("design:type", String)
], AtomicAutomaticFacet.prototype, "field", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: String,
        attribute: 'facet-id',
        reflect: true
    }),
    _ts_metadata("design:type", String)
], AtomicAutomaticFacet.prototype, "facetId", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object,
        reflect: true
    }),
    _ts_metadata("design:type", "u" < typeof AutomaticFacet ? Object : AutomaticFacet)
], AtomicAutomaticFacet.prototype, "facet", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Object,
        attribute: 'search-status',
        reflect: true
    }),
    _ts_metadata("design:type", "u" < typeof SearchStatus ? Object : SearchStatus)
], AtomicAutomaticFacet.prototype, "searchStatus", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        attribute: 'is-collapsed',
        reflect: true
    })
], AtomicAutomaticFacet.prototype, "isCollapsed", 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)
], AtomicAutomaticFacet.prototype, "render", null);
AtomicAutomaticFacet = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-automatic-facet'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles
], AtomicAutomaticFacet);
exports.AtomicAutomaticFacet = __webpack_exports__.AtomicAutomaticFacet;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicAutomaticFacet"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
