import { toJsxRuntime } from "hast-util-to-jsx-runtime";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { JINJA_DOLLAR_PLACEHOLDER, preprocessNormalizeLeafToContainerDirective } from "../MarkdownEditor/editor/parser/constants";
import { debugInfo } from "../Utils/debugUtils";
import { buildEditorAlignedComponents, createHastProcessor } from "./markdownReactShared";
import { useStreamingMarkdownReact } from "./streaming/useStreamingMarkdownReact";
export var useMarkdownToReact = useStreamingMarkdownReact;
/**
 * 同步将 markdown 转为 React 元素（非 hook 版本，用于测试或一次性转换）
 */ export var markdownToReactSync = function markdownToReactSync(content, components, remarkPlugins, htmlConfig) {
    if (!content) return null;
    try {
        var processor = createHastProcessor(remarkPlugins, htmlConfig);
        var preprocessed = preprocessNormalizeLeafToContainerDirective(content.replace(new RegExp(JINJA_DOLLAR_PLACEHOLDER, 'g'), '$'));
        var mdast = processor.parse(preprocessed);
        var hast = processor.runSync(mdast);
        var userComps = components || {};
        var allComponents = buildEditorAlignedComponents('ant-agentic-md-editor', userComps, false, undefined, undefined, false);
        return toJsxRuntime(hast, {
            Fragment: Fragment,
            jsx: jsx,
            jsxs: jsxs,
            components: allComponents,
            passNode: true
        });
    } catch (error) {
        debugInfo('[MarkdownRenderer] markdownToReactSync failed', {
            error: (error === null || error === void 0 ? void 0 : error.message) || String(error)
        });
        return null;
    }
};
