const buildQuickviewPreviewBar = (words, highlightKeywords, iframe)=>{
    if (!iframe) return;
    const documentWriter = iframe.contentDocument;
    if (!documentWriter) return;
    const bar = buildPreviewBar(documentWriter);
    if (highlightKeywords.highlightNone) return void bar.remove();
    const docHeight = documentWriter.body.scrollHeight;
    Object.values(words).forEach((word)=>{
        word.elements.forEach((wordElement)=>{
            const previewUnit = buildPreviewUnit(documentWriter, word, wordElement, docHeight, highlightKeywords);
            bar.appendChild(previewUnit);
        });
    });
    documentWriter.body.appendChild(bar);
};
const buildPreviewBar = (documentWriter)=>{
    const previewBarId = 'CoveoPreviewBar';
    const bar = documentWriter.getElementById(previewBarId) || documentWriter.createElement('div');
    bar.id = previewBarId;
    bar.innerHTML = '';
    bar.style.position = 'fixed';
    bar.style.top = '0';
    bar.style.right = '0';
    bar.style.width = '15px';
    bar.style.height = '100%';
    bar.setAttribute('aria-hidden', 'true');
    return bar;
};
const buildPreviewUnit = (documentWriter, word, wordElement, docHeight, highlightKeywords)=>{
    const previewUnit = documentWriter.createElement('div');
    if (highlightKeywords.keywords[word.text]?.enabled === false) {
        previewUnit.style.display = 'none';
        return previewUnit;
    }
    const elementPosition = wordElement.getBoundingClientRect().top;
    previewUnit.style.position = 'absolute';
    previewUnit.style.top = `${elementPosition / docHeight * 100}%`;
    previewUnit.style.width = '100%';
    previewUnit.style.height = '1px';
    previewUnit.style.border = `1px solid ${word.previewBorderColor}`;
    previewUnit.style.backgroundColor = word.color;
    return previewUnit;
};
export { buildQuickviewPreviewBar };
