/**
 * Parses suggestion text containing <mark>...</mark> and returns React nodes
 * with the marked segments rendered as styled elements. Safe: inner content
 * is rendered as text, not HTML.
 */
import React from 'react';
const defaultMarkStyle = {
    backgroundColor: 'var(--seekora-highlight-bg, rgba(251, 191, 36, 0.4))',
    fontWeight: 500,
    borderRadius: '2px',
    padding: '0 2px',
};
/** Compute styles based on highlight options */
function computeHighlightStyles(options) {
    const style = options.highlightStyle || 'background';
    const base = {};
    switch (style) {
        case 'background':
            base.backgroundColor = options.highlightColor || 'var(--seekora-highlight-bg, rgba(251, 191, 36, 0.4))';
            base.borderRadius = '2px';
            base.padding = '0 2px';
            break;
        case 'underline':
            base.textDecoration = 'underline';
            base.textDecorationColor = options.highlightColor || 'var(--seekora-highlight-bg, rgba(251, 191, 36, 0.8))';
            base.textUnderlineOffset = '2px';
            break;
        case 'bold':
            // Only bold, no background
            break;
        case 'color-only':
            // Only color, no background
            break;
    }
    if (options.highlightTextColor) {
        base.color = options.highlightTextColor;
    }
    else {
        base.color = 'var(--seekora-highlight-color, inherit)';
    }
    base.fontWeight = options.highlightFontWeight || 'var(--seekora-highlight-weight, 500)';
    return base;
}
/**
 * Converts a string like "lined <mark>blue</mark>" into React nodes with
 * the marked part rendered as a styled element. When no <mark> tags are
 * present, returns the string as-is.
 */
export function parseHighlightMarkup(text, options = {}) {
    if (text == null || typeof text !== 'string')
        return text;
    const parts = text.split(/(<mark>[\s\S]*?<\/mark>)/g);
    if (parts.length <= 1)
        return text;
    const { markClassName, markStyle, highlightTag } = options;
    const Tag = (highlightTag || 'mark');
    // Compute styles: if no custom options provided, use legacy defaults
    const hasCustomOptions = options.highlightColor || options.highlightTextColor
        || options.highlightFontWeight || options.highlightStyle;
    const computedStyle = hasCustomOptions
        ? computeHighlightStyles(options)
        : defaultMarkStyle;
    return (React.createElement(React.Fragment, null, parts.map((part, i) => {
        const m = part.match(/^<mark>([\s\S]*)<\/mark>$/);
        if (m) {
            return (React.createElement(Tag, { key: i, className: markClassName, style: { ...computedStyle, ...markStyle } }, m[1]));
        }
        return part;
    })));
}
