"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    TextParser: ()=>TextParser
});
class TextParser {
    parse(element) {
        const innerTextOfHTMLElement = this.getHighlightedInnerText(element);
        return this.resolveOriginalTerm(innerTextOfHTMLElement).trim();
    }
    isTaggedWord(element) {
        return 'coveotaggedword' === element.nodeName.toLowerCase();
    }
    getHighlightedInnerText(element) {
        if (!this.isTaggedWord(element)) return this.getTextOfHTMLElement(element);
        const children = Array.from(element.children);
        if (children.length >= 1) return this.getTextOfHTMLElement(children[0]);
        return '';
    }
    getTextOfHTMLElement(el) {
        return el.innerText || el.textContent || '';
    }
    resolveOriginalTerm(highlight) {
        const found = Object.keys(this.stemmingInfoFromIndex).find((originalTerm)=>{
            const originalTermMatch = originalTerm.toLowerCase() === highlight.toLowerCase();
            if (originalTermMatch) return true;
            const stemmingExpansions = this.stemmingInfoFromIndex[originalTerm];
            if (!stemmingExpansions) return false;
            const stemmingExpansionMatch = stemmingExpansions.find((stemmingExpansion)=>stemmingExpansion.toLowerCase() === highlight.toLowerCase());
            return stemmingExpansionMatch;
        });
        return found || highlight;
    }
    constructor(stemmingInfoFromIndex){
        this.stemmingInfoFromIndex = stemmingInfoFromIndex;
    }
}
exports.TextParser = __webpack_exports__.TextParser;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "TextParser"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
