"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__, {
    AtomicTimeframeFacet: ()=>AtomicTimeframeFacet
});
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 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_placeholder_cjs_namespaceObject = require("../../common/facets/facet-placeholder/facet-placeholder.cjs");
const timeframe_facet_common_cjs_namespaceObject = require("../../common/facets/timeframe-facet-common.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");
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 AtomicTimeframeFacet extends external_lit_namespaceObject.LitElement {
    get focusTarget() {
        if (!this.headerFocus) this.headerFocus = new accessibility_utils_cjs_namespaceObject.FocusTargetController(this, this.bindings);
        return this.headerFocus;
    }
    initialize() {
        if (this.tabsIncluded.length > 0 && this.tabsExcluded.length > 0) console.warn('Values for both "tabs-included" and "tabs-excluded" have been provided. This could lead to unexpected behaviors.');
        this.timeframeFacetCommon = new timeframe_facet_common_cjs_namespaceObject.TimeframeFacetCommon({
            facetId: this.facetId,
            host: this,
            bindings: this.bindings,
            label: this.label,
            field: this.field,
            headingLevel: this.headingLevel,
            dependsOn: (0, depends_on_cjs_namespaceObject.parseDependsOn)(this.dependsOn) ? this.dependsOn : {},
            withDatePicker: this.withDatePicker,
            setFacetId: (id)=>{
                this.facetId = id;
                return id;
            },
            getSearchStatusState: ()=>this.searchStatusState,
            buildDependenciesManager: (facetId)=>(0, headless_namespaceObject.buildFacetConditionsManager)(this.bindings.engine, {
                    facetId,
                    conditions: (0, depends_on_cjs_namespaceObject.parseDependsOn)(this.dependsOn)
                }),
            deserializeRelativeDate: headless_namespaceObject.deserializeRelativeDate,
            buildDateRange: headless_namespaceObject.buildDateRange,
            initializeFacetForDatePicker: ()=>this.initializeFacetForDatePicker(),
            initializeFacetForDateRange: (values)=>this.initializeFacetForDateRange(values),
            initializeFilter: ()=>this.initializeFilter(),
            min: this.min,
            max: this.max,
            sortCriteria: this.sortCriteria
        });
        this.searchStatus = (0, headless_namespaceObject.buildSearchStatus)(this.bindings.engine);
        this.tabManager = (0, headless_namespaceObject.buildTabManager)(this.bindings.engine);
        this.addEventListener('atomic-date-input-apply', this.handleDateInputApply);
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.timeframeFacetCommon?.disconnectedCallback();
        this.removeEventListener('atomic-date-input-apply', this.handleDateInputApply);
    }
    initializeFacetForDatePicker() {
        return (0, headless_namespaceObject.buildDateFacet)(this.bindings.engine, {
            options: {
                facetId: `${this.facetId}_input_range`,
                numberOfValues: 1,
                generateAutomaticRanges: true,
                field: this.field,
                filterFacetCount: this.filterFacetCount,
                injectionDepth: this.injectionDepth,
                tabs: {
                    included: this.tabsIncluded,
                    excluded: this.tabsExcluded
                }
            }
        });
    }
    initializeFacetForDateRange(values) {
        return (0, headless_namespaceObject.buildDateFacet)(this.bindings.engine, {
            options: {
                facetId: this.facetId,
                field: this.field,
                currentValues: values,
                generateAutomaticRanges: false,
                sortCriteria: this.sortCriteria,
                filterFacetCount: this.filterFacetCount,
                injectionDepth: this.injectionDepth,
                tabs: {
                    included: this.tabsIncluded,
                    excluded: this.tabsExcluded
                }
            }
        });
    }
    initializeFilter() {
        return (0, headless_namespaceObject.buildDateFilter)(this.bindings.engine, {
            options: {
                facetId: `${this.facetId}_input`,
                field: this.field,
                tabs: {
                    included: this.tabsIncluded,
                    excluded: this.tabsExcluded
                }
            }
        });
    }
    render() {
        return (0, external_lit_namespaceObject.html)`${(0, when_js_namespaceObject.when)(this.timeframeFacetCommon, ()=>this.timeframeFacetCommon.render({
                hasError: this.searchStatusState.hasError,
                firstSearchExecuted: this.searchStatusState.firstSearchExecuted,
                isCollapsed: this.isCollapsed,
                headerFocus: this.focusTarget,
                onToggleCollapse: ()=>{
                    this.isCollapsed = !this.isCollapsed;
                    return this.isCollapsed;
                }
            }), ()=>(0, facet_placeholder_cjs_namespaceObject.renderFacetPlaceholder)({
                props: {
                    numberOfValues: 5,
                    isCollapsed: this.isCollapsed
                }
            }))}`;
    }
    constructor(){
        super(), this.label = 'no-label', this.field = 'date', this.tabsIncluded = [], this.tabsExcluded = [], this.withDatePicker = false, this.isCollapsed = false, this.headingLevel = 0, this.filterFacetCount = true, this.injectionDepth = 1000, this.sortCriteria = 'descending', this.handleDateInputApply = ()=>{
            if (this.facetId) this.bindings.engine.dispatch((0, headless_namespaceObject.loadDateFacetSetActions)(this.bindings.engine).deselectAllDateFacetValues(this.facetId));
        };
        new validate_props_controller_cjs_namespaceObject.ValidatePropsController(this, ()=>({
                injectionDepth: this.injectionDepth,
                headingLevel: this.headingLevel,
                min: this.min,
                max: this.max,
                sortCriteria: this.sortCriteria
            }), AtomicTimeframeFacet.propsSchema, false);
    }
}
AtomicTimeframeFacet.propsSchema = new bueno_namespaceObject.Schema({
    injectionDepth: new bueno_namespaceObject.NumberValue({
        min: 0,
        required: false
    }),
    headingLevel: new bueno_namespaceObject.NumberValue({
        min: 0,
        max: 6,
        required: false
    }),
    min: new bueno_namespaceObject.StringValue({
        required: false,
        emptyAllowed: true
    }),
    max: new bueno_namespaceObject.StringValue({
        required: false,
        emptyAllowed: true
    }),
    sortCriteria: new bueno_namespaceObject.StringValue({
        constrainTo: [
            'ascending',
            'descending'
        ],
        required: false
    })
});
AtomicTimeframeFacet.styles = facet_common_tw_css_cjs_default();
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true
    })
], AtomicTimeframeFacet.prototype, "label", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true
    })
], AtomicTimeframeFacet.prototype, "field", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        converter: array_converter_cjs_namespaceObject.arrayConverter,
        attribute: 'tabs-included'
    }),
    _ts_metadata("design:type", Array)
], AtomicTimeframeFacet.prototype, "tabsIncluded", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        converter: array_converter_cjs_namespaceObject.arrayConverter,
        attribute: 'tabs-excluded'
    }),
    _ts_metadata("design:type", Array)
], AtomicTimeframeFacet.prototype, "tabsExcluded", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        reflect: true,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter,
        attribute: 'with-date-picker'
    })
], AtomicTimeframeFacet.prototype, "withDatePicker", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        reflect: true,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter,
        attribute: 'is-collapsed'
    })
], AtomicTimeframeFacet.prototype, "isCollapsed", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'heading-level'
    })
], AtomicTimeframeFacet.prototype, "headingLevel", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Boolean,
        reflect: true,
        converter: boolean_converter_cjs_namespaceObject.booleanConverter,
        attribute: 'filter-facet-count'
    })
], AtomicTimeframeFacet.prototype, "filterFacetCount", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        reflect: true,
        attribute: 'injection-depth'
    })
], AtomicTimeframeFacet.prototype, "injectionDepth", void 0);
_ts_decorate([
    (0, props_utils_cjs_namespaceObject.mapProperty)({
        attributePrefix: 'depends-on'
    }),
    _ts_metadata("design:type", "u" < typeof Record ? Object : Record)
], AtomicTimeframeFacet.prototype, "dependsOn", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true
    }),
    _ts_metadata("design:type", String)
], AtomicTimeframeFacet.prototype, "min", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true
    }),
    _ts_metadata("design:type", String)
], AtomicTimeframeFacet.prototype, "max", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'sort-criteria'
    }),
    _ts_metadata("design:type", "u" < typeof RangeFacetSortCriterion ? Object : RangeFacetSortCriterion)
], AtomicTimeframeFacet.prototype, "sortCriteria", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        reflect: true,
        attribute: 'facet-id'
    }),
    _ts_metadata("design:type", String)
], AtomicTimeframeFacet.prototype, "facetId", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Bindings ? Object : Bindings)
], AtomicTimeframeFacet.prototype, "bindings", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicTimeframeFacet.prototype, "error", 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)
], AtomicTimeframeFacet.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)
], AtomicTimeframeFacet.prototype, "tabManagerState", 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)
], AtomicTimeframeFacet.prototype, "render", null);
AtomicTimeframeFacet = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-timeframe-facet'),
    (0, bindings_cjs_namespaceObject.bindings)(),
    with_tailwind_styles_cjs_namespaceObject.withTailwindStyles,
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", [])
], AtomicTimeframeFacet);
exports.AtomicTimeframeFacet = __webpack_exports__.AtomicTimeframeFacet;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicTimeframeFacet"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
