'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from 'react';
import { IhelpIcon } from './ihelp_icon.js';
/**
 * Parses a description string containing {ihelp:context_key}text{/ihelp} markers
 * and renders inline text with IhelpIcon components.
 *
 * Example:
 *   "Provide details of {ihelp:dividends_help}dividends{/ihelp}, {ihelp:dist_help}distributions{/ihelp}"
 *
 * Renders: "Provide details of dividends ℹ️, distributions ℹ️"
 */
export function DescriptionWithIhelp({ description, className, ihelp_size = 13, }) {
    const parts = parse_description_ihelp(description);
    // No ihelp markers found — render plain text
    if (parts.length === 1 && parts[0].type === 'text') {
        return _jsx("p", { className: className, children: parts[0].content });
    }
    return (_jsx("p", { className: className, children: parts.map((part, i) => part.type === 'text' ? (_jsx(React.Fragment, { children: part.content }, i)) : (_jsxs("span", { className: "inline-flex items-center gap-0.5", children: [part.content, _jsx(IhelpIcon, { context_key: part.context_key, size: ihelp_size })] }, i))) }));
}
function parse_description_ihelp(description) {
    const pattern = /\{ihelp:([^}]+)\}(.*?)\{\/ihelp\}/g;
    const parts = [];
    let last_index = 0;
    let match;
    while ((match = pattern.exec(description)) !== null) {
        // Text before this match
        if (match.index > last_index) {
            parts.push({ type: 'text', content: description.slice(last_index, match.index) });
        }
        parts.push({ type: 'ihelp', content: match[2], context_key: match[1] });
        last_index = match.index + match[0].length;
    }
    // Remaining text after last match
    if (last_index < description.length) {
        parts.push({ type: 'text', content: description.slice(last_index) });
    }
    // No matches at all
    if (parts.length === 0) {
        parts.push({ type: 'text', content: description });
    }
    return parts;
}
//# sourceMappingURL=description_with_ihelp.js.map