function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
function _object_without_properties(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys, key, i;
    if (typeof Reflect !== "undefined" && Reflect.ownKeys) {
        sourceKeys = Reflect.ownKeys(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
        return target;
    }
    target = _object_without_properties_loose(source, excluded);
    if (Object.getOwnPropertySymbols) {
        sourceKeys = Object.getOwnPropertySymbols(source);
        for(i = 0; i < sourceKeys.length; i++){
            key = sourceKeys[i];
            if (excluded.indexOf(key) >= 0) continue;
            if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
            target[key] = source[key];
        }
    }
    return target;
}
function _object_without_properties_loose(source, excluded) {
    if (source == null) return {};
    var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i;
    for(i = 0; i < sourceKeys.length; i++){
        key = sourceKeys[i];
        if (excluded.indexOf(key) >= 0) continue;
        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
        target[key] = source[key];
    }
    return target;
}
import React, { lazy, Suspense, useMemo } from "react";
import { extractBlockTextContent } from "./extractBlockTextContent";
var LazyMermaidBlockRenderer = /*#__PURE__*/ lazy(function() {
    return import("./renderers/MermaidRenderer").then(function(m) {
        return {
            default: m.MermaidBlockRenderer
        };
    });
});
var LazyChartBlockRenderer = /*#__PURE__*/ lazy(function() {
    return import("./renderers/ChartRenderer").then(function(m) {
        return {
            default: m.ChartBlockRenderer
        };
    });
});
var LazyCodeBlockRenderer = /*#__PURE__*/ lazy(function() {
    return import("./renderers/CodeRenderer").then(function(m) {
        return {
            default: m.CodeBlockRenderer
        };
    });
});
var LazySchemaBlockRenderer = /*#__PURE__*/ lazy(function() {
    return import("./renderers/SchemaRenderer").then(function(m) {
        return {
            default: m.SchemaBlockRenderer
        };
    });
});
var LazyAgenticUiTaskBlockRenderer = /*#__PURE__*/ lazy(function() {
    return import("./renderers/AgenticUiTaskBlockRenderer").then(function(m) {
        return {
            default: m.AgenticUiTaskBlockRenderer
        };
    });
});
var LazyAgenticUiToolUseBarBlockRenderer = /*#__PURE__*/ lazy(function() {
    return import("./renderers/AgenticUiToolUseBarBlockRenderer").then(function(m) {
        return {
            default: m.AgenticUiToolUseBarBlockRenderer
        };
    });
});
var LazyAgenticUiFileMapBlockRenderer = /*#__PURE__*/ lazy(function() {
    return import("./renderers/AgenticUiFileMapBlockRenderer").then(function(m) {
        return {
            default: m.AgenticUiFileMapBlockRenderer
        };
    });
});
var SCHEMA_LANGUAGES = new Set([
    'schema',
    'apaasify',
    'apassify',
    'agentar-card'
]);
var CodeBlockLazyFallback = function CodeBlockLazyFallback(props) {
    var code = useMemo(function() {
        return extractBlockTextContent(props.children);
    }, [
        props.children
    ]);
    return /*#__PURE__*/ React.createElement("pre", {
        className: "agentic-md-renderer-fallback",
        style: {
            margin: '0.5em 0',
            padding: '0.75em 1em',
            overflow: 'auto',
            fontSize: '0.875em',
            lineHeight: 1.5,
            background: 'var(--ant-color-fill-quaternary, #f5f5f5)',
            borderRadius: 6,
            whiteSpace: 'pre-wrap',
            wordBreak: 'break-word'
        }
    }, /*#__PURE__*/ React.createElement("code", null, code));
};
/**
 * 默认的代码块路由：内置渲染器使用 React.lazy 分包，插件提供的 renderer 仍同步加载。
 */ export var DefaultCodeRouter = function DefaultCodeRouter(props) {
    var language = props.language, pluginComponents = props.pluginComponents, apaasifyRender = props.apaasifyRender, fileMapConfig = props.fileMapConfig, editorCodeProps = props.editorCodeProps, rest = _object_without_properties(props, [
        "language",
        "pluginComponents",
        "apaasifyRender",
        "fileMapConfig",
        "editorCodeProps"
    ]);
    if (language === 'mermaid') {
        if (pluginComponents.mermaid) {
            var C = pluginComponents.mermaid;
            return /*#__PURE__*/ React.createElement(C, _object_spread_props(_object_spread({}, rest), {
                language: language
            }));
        }
        return /*#__PURE__*/ React.createElement(Suspense, {
            fallback: /*#__PURE__*/ React.createElement(CodeBlockLazyFallback, _object_spread_props(_object_spread({}, rest), {
                language: language
            }))
        }, /*#__PURE__*/ React.createElement(LazyMermaidBlockRenderer, _object_spread_props(_object_spread({}, rest), {
            language: language
        })));
    }
    if (language === 'chart' || language === 'json-chart') {
        if (pluginComponents.chart) {
            var C1 = pluginComponents.chart;
            return /*#__PURE__*/ React.createElement(C1, _object_spread_props(_object_spread({}, rest), {
                language: language
            }));
        }
        return /*#__PURE__*/ React.createElement(Suspense, {
            fallback: /*#__PURE__*/ React.createElement(CodeBlockLazyFallback, _object_spread_props(_object_spread({}, rest), {
                language: language
            }))
        }, /*#__PURE__*/ React.createElement(LazyChartBlockRenderer, _object_spread_props(_object_spread({}, rest), {
            language: language
        })));
    }
    if (language === 'agentic-ui-task') {
        if (pluginComponents['agentic-ui-task']) {
            var C2 = pluginComponents['agentic-ui-task'];
            return /*#__PURE__*/ React.createElement(C2, _object_spread_props(_object_spread({}, rest), {
                language: language
            }));
        }
        return /*#__PURE__*/ React.createElement(Suspense, {
            fallback: /*#__PURE__*/ React.createElement(CodeBlockLazyFallback, _object_spread_props(_object_spread({}, rest), {
                language: language
            }))
        }, /*#__PURE__*/ React.createElement(LazyAgenticUiTaskBlockRenderer, _object_spread_props(_object_spread({}, rest), {
            language: language
        })));
    }
    if (language === 'agentic-ui-toolusebar' || language === 'agentic-ui-usertoolbar') {
        if (pluginComponents['agentic-ui-toolusebar'] || pluginComponents['agentic-ui-usertoolbar']) {
            var C3 = pluginComponents['agentic-ui-toolusebar'] || pluginComponents['agentic-ui-usertoolbar'];
            return /*#__PURE__*/ React.createElement(C3, _object_spread_props(_object_spread({}, rest), {
                language: language
            }));
        }
        return /*#__PURE__*/ React.createElement(Suspense, {
            fallback: /*#__PURE__*/ React.createElement(CodeBlockLazyFallback, _object_spread_props(_object_spread({}, rest), {
                language: language
            }))
        }, /*#__PURE__*/ React.createElement(LazyAgenticUiToolUseBarBlockRenderer, _object_spread_props(_object_spread({}, rest), {
            language: language
        })));
    }
    if (language === 'agentic-ui-filemap') {
        if (pluginComponents['agentic-ui-filemap']) {
            var C4 = pluginComponents['agentic-ui-filemap'];
            return /*#__PURE__*/ React.createElement(C4, _object_spread_props(_object_spread({}, rest), {
                language: language,
                fileMapConfig: fileMapConfig
            }));
        }
        return /*#__PURE__*/ React.createElement(Suspense, {
            fallback: /*#__PURE__*/ React.createElement(CodeBlockLazyFallback, _object_spread_props(_object_spread({}, rest), {
                language: language
            }))
        }, /*#__PURE__*/ React.createElement(LazyAgenticUiFileMapBlockRenderer, _object_spread_props(_object_spread({}, rest), {
            language: language,
            fileMapConfig: fileMapConfig
        })));
    }
    if (language && SCHEMA_LANGUAGES.has(language)) {
        if (pluginComponents.schema) {
            var C5 = pluginComponents.schema;
            return /*#__PURE__*/ React.createElement(C5, _object_spread_props(_object_spread({}, rest), {
                language: language,
                apaasifyRender: apaasifyRender,
                editorCodeProps: editorCodeProps
            }));
        }
        return /*#__PURE__*/ React.createElement(Suspense, {
            fallback: /*#__PURE__*/ React.createElement(CodeBlockLazyFallback, _object_spread_props(_object_spread({}, rest), {
                language: language
            }))
        }, /*#__PURE__*/ React.createElement(LazySchemaBlockRenderer, _object_spread_props(_object_spread({}, rest), {
            language: language,
            apaasifyRender: apaasifyRender,
            editorCodeProps: editorCodeProps
        })));
    }
    if (pluginComponents.code) {
        var C6 = pluginComponents.code;
        return /*#__PURE__*/ React.createElement(C6, _object_spread_props(_object_spread({}, rest), {
            language: language,
            editorCodeProps: editorCodeProps
        }));
    }
    return /*#__PURE__*/ React.createElement(Suspense, {
        fallback: /*#__PURE__*/ React.createElement(CodeBlockLazyFallback, _object_spread_props(_object_spread({}, rest), {
            language: language
        }))
    }, /*#__PURE__*/ React.createElement(LazyCodeBlockRenderer, _object_spread_props(_object_spread({}, rest), {
        language: language,
        editorCodeProps: editorCodeProps
    })));
};
export default DefaultCodeRouter;
