import React, { useMemo } from "react";
import { MermaidRendererImpl } from "../../Plugins/mermaid/MermaidRendererImpl";
var extractTextContent = function extractTextContent1(children) {
    var _children_props;
    if (typeof children === 'string') return children;
    if (typeof children === 'number') return String(children);
    if (Array.isArray(children)) return children.map(extractTextContent).join('');
    if (/*#__PURE__*/ React.isValidElement(children) && ((_children_props = children.props) === null || _children_props === void 0 ? void 0 : _children_props.children)) {
        return extractTextContent(children.props.children);
    }
    return '';
};
/**
 * Mermaid 图表渲染器——复用 MarkdownEditor 的 MermaidRendererImpl。
 * 将代码块文本包装为 CodeNode 格式后直接传递给已有的 Mermaid 渲染组件。
 */ export var MermaidBlockRenderer = function MermaidBlockRenderer(props) {
    var children = props.children;
    var code = extractTextContent(children);
    var fakeElement = useMemo(function() {
        return {
            type: 'code',
            language: 'mermaid',
            value: code,
            children: [
                {
                    text: code
                }
            ]
        };
    }, [
        code
    ]);
    if (!code.trim()) return null;
    return /*#__PURE__*/ React.createElement("div", {
        "data-be": "mermaid",
        style: {
            margin: '1em 0'
        }
    }, /*#__PURE__*/ React.createElement(MermaidRendererImpl, {
        element: fakeElement
    }));
};
MermaidBlockRenderer.displayName = 'MermaidBlockRenderer';
