import { ColorParser } from "./color-parser.js";
class QuickviewWordHighlight {
    addElement(element) {
        this.elements.push(element);
    }
    get occurrences() {
        return this.elements.length;
    }
    navigateForward() {
        this.currentNavigationPosition++;
        if (this.currentNavigationPosition >= this.elements.length) this.currentNavigationPosition = 0;
        this.highlightNavigation();
        this.putElementIntoView();
        return this.elements[this.currentNavigationPosition];
    }
    navigateBackward() {
        this.currentNavigationPosition--;
        if (this.currentNavigationPosition < 0) this.currentNavigationPosition = this.elements.length - 1;
        this.highlightNavigation();
        this.putElementIntoView();
        return this.elements[this.currentNavigationPosition];
    }
    highlightNavigation() {
        const currentElement = this.elements[this.currentNavigationPosition];
        const otherElements = this.elements.filter((el)=>el !== currentElement);
        currentElement.style.color = this.color;
        currentElement.style.backgroundColor = this.focusedColor;
        otherElements.forEach((element)=>{
            element.style.color = '';
            element.style.backgroundColor = this.color;
        });
    }
    putElementIntoView() {
        const element = this.elements[this.currentNavigationPosition];
        element.scrollIntoView();
    }
    constructor(indexIdentifier, text, color, element){
        this.indexIdentifier = indexIdentifier;
        this.text = text;
        this.color = color;
        this.elements = [];
        this.currentNavigationPosition = -1;
        this.addElement(element);
        const colorParser = new ColorParser(color);
        this.focusedColor = colorParser.rgbInverted();
        this.previewBorderColor = colorParser.rgbSaturated();
    }
}
export { HIGHLIGHT_PREFIX, getWordsHighlights } from "./iframe-parser.js";
export { QuickviewWordHighlight };
