"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__, {
    AtomicSearchBoxQuerySuggestions: ()=>AtomicSearchBoxQuerySuggestions
});
const headless_namespaceObject = require("@coveo/headless");
const external_lit_namespaceObject = require("lit");
const decorators_js_namespaceObject = require("lit/decorators.js");
const query_suggestions_cjs_namespaceObject = require("../../common/suggestions/query-suggestions.cjs");
const suggestions_events_cjs_namespaceObject = require("../../common/suggestions/suggestions-events.cjs");
const error_guard_cjs_namespaceObject = require("../../../decorators/error-guard.cjs");
const search_cjs_namespaceObject = require("../../../images/search.cjs");
var search_cjs_default = /*#__PURE__*/ __webpack_require__.n(search_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 AtomicSearchBoxQuerySuggestions extends external_lit_namespaceObject.LitElement {
    connectedCallback() {
        try {
            super.connectedCallback();
        } catch (error) {
            this.error = error;
            return;
        }
        try {
            (0, suggestions_events_cjs_namespaceObject.dispatchSearchBoxSuggestionsEvent)((bindings)=>{
                this.bindings = bindings;
                return this.initialize();
            }, this, [
                'atomic-search-box'
            ]);
        } catch (error) {
            this.error = error;
        }
    }
    initialize() {
        const engine = this.bindings.engine;
        const { registerQuerySuggest, fetchQuerySuggestions } = (0, headless_namespaceObject.loadQuerySuggestActions)(engine);
        const numberOfQueries = this.bindings.numberOfQueries;
        const maxWithQuery = this.maxWithQuery;
        if (void 0 !== maxWithQuery && numberOfQueries < maxWithQuery) {
            const logger = this.bindings.engine.logger;
            logger.warn(`Query suggestions config mismatch: number-of-queries (${numberOfQueries}) < max-with-query (${maxWithQuery}). Update one to match the other.`);
        }
        engine.dispatch(registerQuerySuggest({
            id: this.bindings.id,
            count: this.bindings.numberOfQueries
        }));
        return {
            position: Array.from(this.parentNode.children).indexOf(this),
            onInput: ()=>engine.dispatch(fetchQuerySuggestions({
                    id: this.bindings.id
                })),
            renderItems: ()=>this.renderItems()
        };
    }
    renderItems() {
        const hasQuery = '' !== this.bindings.searchBoxController.state.value;
        const max = hasQuery ? this.maxWithQuery : this.maxWithoutQuery;
        return this.bindings.searchBoxController.state.suggestions.slice(0, max).map((suggestion)=>this.renderItem(suggestion));
    }
    renderItem(suggestion) {
        const partialItem = (0, query_suggestions_cjs_namespaceObject.getPartialSearchBoxSuggestionElement)(suggestion, this.bindings.i18n);
        const icon = this.icon ? this.icon : search_cjs_default();
        const hasQuery = '' !== this.bindings.searchBoxController.state.value;
        const hasMultipleKindOfSuggestions = this.bindings.getSuggestions().length > 1;
        return {
            ...partialItem,
            content: (0, query_suggestions_cjs_namespaceObject.renderQuerySuggestion)({
                icon,
                hasQuery,
                suggestion,
                hasMultipleKindOfSuggestions
            }),
            onSelect: ()=>{
                this.bindings.searchBoxController.selectSuggestion(suggestion.rawValue);
            }
        };
    }
    render() {
        return external_lit_namespaceObject.nothing;
    }
}
_ts_decorate([
    (0, decorators_js_namespaceObject.state)(),
    _ts_metadata("design:type", "u" < typeof Error ? Object : Error)
], AtomicSearchBoxQuerySuggestions.prototype, "error", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)(),
    _ts_metadata("design:type", String)
], AtomicSearchBoxQuerySuggestions.prototype, "icon", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        attribute: 'max-with-query',
        reflect: true
    }),
    _ts_metadata("design:type", Number)
], AtomicSearchBoxQuerySuggestions.prototype, "maxWithQuery", void 0);
_ts_decorate([
    (0, decorators_js_namespaceObject.property)({
        type: Number,
        attribute: 'max-without-query',
        reflect: true
    }),
    _ts_metadata("design:type", Number)
], AtomicSearchBoxQuerySuggestions.prototype, "maxWithoutQuery", void 0);
_ts_decorate([
    (0, error_guard_cjs_namespaceObject.errorGuard)(),
    _ts_metadata("design:type", Function),
    _ts_metadata("design:paramtypes", []),
    _ts_metadata("design:returntype", void 0)
], AtomicSearchBoxQuerySuggestions.prototype, "render", null);
AtomicSearchBoxQuerySuggestions = _ts_decorate([
    (0, decorators_js_namespaceObject.customElement)('atomic-search-box-query-suggestions')
], AtomicSearchBoxQuerySuggestions);
exports.AtomicSearchBoxQuerySuggestions = __webpack_exports__.AtomicSearchBoxQuerySuggestions;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "AtomicSearchBoxQuerySuggestions"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
