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 _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 { normalizeToolUseBarPropsFromJson } from "../../MarkdownEditor/editor/elements/AgenticUiBlocks/agenticUiEmbedUtils";
import { ToolUseBar } from "../../ToolUseBar";
import { extractBlockTextContent } from "../extractBlockTextContent";
import { parseJsonBody } from "./utils/parseJsonBody";
import { RendererJsonFallback } from "./utils/RendererJsonFallback";
/**
 * ```agentic-ui-toolusebar``` 代码块 → ToolUseBar
 */ export var AgenticUiToolUseBarBlockRenderer = function AgenticUiToolUseBarBlockRenderer(props) {
    var code = useMemo(function() {
        return extractBlockTextContent(props.children);
    }, [
        props.children
    ]);
    var parsed = useMemo(function() {
        return parseJsonBody(code);
    }, [
        code
    ]);
    var _useMemo = useMemo(function() {
        return normalizeToolUseBarPropsFromJson(parsed);
    }, [
        parsed
    ]), tools = _useMemo.tools, restBar = _object_without_properties(_useMemo, [
        "tools"
    ]);
    if (parsed === null) {
        return /*#__PURE__*/ React.createElement(RendererJsonFallback, {
            testId: "agentic-ui-toolusebar-fallback",
            code: code
        });
    }
    return /*#__PURE__*/ React.createElement("div", {
        "data-testid": "agentic-ui-toolusebar-block",
        style: {
            margin: '0.75em 0'
        }
    }, /*#__PURE__*/ React.createElement(ToolUseBar, _object_spread({
        tools: tools
    }, restBar)));
};
AgenticUiToolUseBarBlockRenderer.displayName = 'AgenticUiToolUseBarBlockRenderer';
