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, { useMemo } from "react";
import { normalizeFileMapPropsFromJson } from "../../MarkdownEditor/editor/elements/AgenticUiBlocks/agenticUiEmbedUtils";
import { FileMapView } from "../../MarkdownInputField/FileMapView";
import { extractBlockTextContent } from "../extractBlockTextContent";
import { parseJsonBody } from "./utils/parseJsonBody";
import { RendererJsonFallback } from "./utils/RendererJsonFallback";
/**
 * ```agentic-ui-filemap``` 代码块 → FileMapView
 */ export var AgenticUiFileMapBlockRenderer = function AgenticUiFileMapBlockRenderer(props) {
    var fileMapConfig = props.fileMapConfig, rest = _object_without_properties(props, [
        "fileMapConfig"
    ]);
    var code = useMemo(function() {
        return extractBlockTextContent(rest.children);
    }, [
        rest.children
    ]);
    var parsed = useMemo(function() {
        return parseJsonBody(code);
    }, [
        code
    ]);
    var _useMemo = useMemo(function() {
        return normalizeFileMapPropsFromJson(parsed, fileMapConfig === null || fileMapConfig === void 0 ? void 0 : fileMapConfig.normalizeFile);
    }, [
        parsed,
        fileMapConfig === null || fileMapConfig === void 0 ? void 0 : fileMapConfig.normalizeFile
    ]), fileList = _useMemo.fileList, className = _useMemo.className;
    var fileMap = useMemo(function() {
        return new Map(fileList.map(function(f) {
            return [
                f.uuid || f.name,
                f
            ];
        }));
    }, [
        fileList
    ]);
    if (parsed === null) {
        return /*#__PURE__*/ React.createElement(RendererJsonFallback, {
            testId: "agentic-ui-filemap-fallback",
            code: code
        });
    }
    return /*#__PURE__*/ React.createElement("div", {
        "data-testid": "agentic-ui-filemap-block",
        style: {
            margin: '0.75em 0'
        }
    }, /*#__PURE__*/ React.createElement(FileMapView, {
        fileMap: fileMap,
        className: className,
        onPreview: fileMapConfig === null || fileMapConfig === void 0 ? void 0 : fileMapConfig.onPreview,
        itemRender: fileMapConfig === null || fileMapConfig === void 0 ? void 0 : fileMapConfig.itemRender
    }));
};
AgenticUiFileMapBlockRenderer.displayName = 'AgenticUiFileMapBlockRenderer';
