function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_with_holes(arr) {
    if (Array.isArray(arr)) return arr;
}
function _array_without_holes(arr) {
    if (Array.isArray(arr)) return _array_like_to_array(arr);
}
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 _iterable_to_array(iter) {
    if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _iterable_to_array_limit(arr, i) {
    var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
    if (_i == null) return;
    var _arr = [];
    var _n = true;
    var _d = false;
    var _s, _e;
    try {
        for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
            _arr.push(_s.value);
            if (i && _arr.length === i) break;
        }
    } catch (err) {
        _d = true;
        _e = err;
    } finally{
        try {
            if (!_n && _i["return"] != null) _i["return"]();
        } finally{
            if (_d) throw _e;
        }
    }
    return _arr;
}
function _non_iterable_rest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _non_iterable_spread() {
    throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
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;
}
function _sliced_to_array(arr, i) {
    return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _to_consumable_array(arr) {
    return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { ConfigProvider } from "antd";
import classNames from "clsx";
import { useMergedState } from "rc-util";
import React, { memo, useContext, useMemo } from "react";
import { useRefFunction } from "../Hooks/useRefFunction";
import { ToolUseBarItem } from "./BarItem";
import { useStyle } from "./style";
export * from "./BarItem";
/**
 * ToolUseBar 组件 - 工具使用栏组件
 *
 * 该组件显示工具使用列表，支持工具的展开/折叠、激活状态管理等功能。
 * 每个工具项显示工具名称、目标、时间等信息，支持点击交互。
 *
 * @component
 * @description 工具使用栏组件，显示工具使用列表和状态
 * @param {ToolUseBarProps} props - 组件属性
 * @param {ToolUseItem[]} [props.tools] - 工具使用列表
 * @param {string[]} [props.activeKeys] - 当前激活的工具ID列表
 * @param {string[]} [props.defaultActiveKeys] - 默认激活的工具ID列表
 * @param {(keys: string[]) => void} [props.onActiveKeysChange] - 激活状态变化回调
 * @param {string[]} [props.expandedKeys] - 当前展开的工具ID列表
 * @param {string[]} [props.defaultExpandedKeys] - 默认展开的工具ID列表
 * @param {(keys: string[]) => void} [props.onExpandedKeysChange] - 展开状态变化回调
 * @param {(tool: ToolUseItem) => void} [props.onToolClick] - 工具点击回调
 * @param {string} [props.className] - 自定义CSS类名
 * @param {React.CSSProperties} [props.style] - 自定义样式，可用于设置固定宽度和高度以防止页面抖动
 *
 * @example
 * ```tsx
 * <ToolUseBar
 *   tools={toolList}
 *   activeKeys={['tool1', 'tool2']}
 *   onActiveKeysChange={(keys) => setActiveKeys(keys)}
 *   expandedKeys={['tool1']}
 *   onExpandedKeysChange={(keys) => setExpandedKeys(keys)}
 *   onToolClick={(tool) => console.log('点击工具:', tool.toolName)}
 * />
 * ```
 *
 * @returns {React.ReactElement} 渲染的工具使用栏组件
 *
 * @remarks
 * - 支持工具列表的受控和非受控展开/折叠
 * - 支持工具的受控和非受控激活状态管理
 * - 显示工具名称、目标、时间等信息
 * - 支持工具点击交互
 * - 提供加载状态显示
 * - 支持错误状态处理
 */ var ToolUseBarComponent = function ToolUseBarComponent(_0) {
    var tools = _0.tools, onActiveKeysChange = _0.onActiveKeysChange, onExpandedKeysChange = _0.onExpandedKeysChange, _0_light = _0.light, light = _0_light === void 0 ? false : _0_light, _0_disableAnimation = _0.disableAnimation, disableAnimation = _0_disableAnimation === void 0 ? false : _0_disableAnimation, style = _0.style, testId = _0.testId, props = _object_without_properties(_0, [
        "tools",
        "onActiveKeysChange",
        "onExpandedKeysChange",
        "light",
        "disableAnimation",
        "style",
        "testId"
    ]);
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var prefixCls = getPrefixCls('agentic-tool-use-bar');
    var _useStyle = useStyle(prefixCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    var _useMergedState = _sliced_to_array(useMergedState(props.defaultActiveKeys || [], {
        value: props.activeKeys,
        defaultValue: props.defaultActiveKeys,
        onChange: onActiveKeysChange
    }), 2), activeKeys = _useMergedState[0], setActiveKeys = _useMergedState[1];
    var _useMergedState1 = _sliced_to_array(useMergedState(props.defaultExpandedKeys || [], {
        value: props.expandedKeys,
        onChange: onExpandedKeysChange
    }), 2), expandedKeys = _useMergedState1[0], setExpandedKeys = _useMergedState1[1];
    var handleActiveChange = useRefFunction(function(id, active) {
        if (onActiveKeysChange) {
            var newActiveKeys = active ? _to_consumable_array(activeKeys).concat([
                id
            ]) : activeKeys.filter(function(key) {
                return key !== id;
            });
            setActiveKeys(newActiveKeys);
        }
    });
    var handleExpandedChange = useRefFunction(function(id, expanded) {
        var newExpandedKeys = expanded ? _to_consumable_array(expandedKeys).concat([
            id
        ]) : expandedKeys.filter(function(key) {
            return key !== id;
        });
        // 计算被移除的键
        var removedKeys = expandedKeys.filter(function(key) {
            return !newExpandedKeys.includes(key);
        });
        setExpandedKeys(newExpandedKeys);
        // 调用回调函数，传递新的展开键列表和被移除的键列表
        if (onExpandedKeysChange) {
            onExpandedKeysChange(newExpandedKeys, removedKeys);
        }
    });
    // 使用 useMemo 优化工具列表的渲染
    var toolItems = useMemo(function() {
        if (!(tools === null || tools === void 0 ? void 0 : tools.length)) return null;
        return tools.map(function(tool) {
            var _props_defaultExpandedKeys;
            return /*#__PURE__*/ React.createElement(ToolUseBarItem, {
                key: tool.id,
                tool: tool,
                onClick: props.onToolClick,
                isActive: activeKeys.includes(tool.id),
                onActiveChange: handleActiveChange,
                isExpanded: onExpandedKeysChange ? expandedKeys.includes(tool.id) : undefined,
                onExpandedChange: onExpandedKeysChange ? handleExpandedChange : undefined,
                defaultExpanded: (_props_defaultExpandedKeys = props.defaultExpandedKeys) === null || _props_defaultExpandedKeys === void 0 ? void 0 : _props_defaultExpandedKeys.includes(tool.id),
                prefixCls: prefixCls,
                hashId: hashId,
                light: light,
                disableAnimation: disableAnimation
            });
        });
    }, [
        tools,
        props.onToolClick,
        activeKeys,
        handleActiveChange,
        onExpandedKeysChange,
        expandedKeys,
        handleExpandedChange,
        props.defaultExpandedKeys,
        prefixCls,
        hashId,
        light,
        disableAnimation
    ]);
    // 使用 useMemo 优化样式类名
    var containerClassName = useMemo(function() {
        return classNames(prefixCls, hashId, props.className, _define_property({}, "".concat(prefixCls, "-no-animation"), disableAnimation));
    }, [
        prefixCls,
        hashId,
        props.className,
        disableAnimation
    ]);
    if (!(tools === null || tools === void 0 ? void 0 : tools.length)) return /*#__PURE__*/ React.createElement("div", {
        className: containerClassName,
        "data-testid": testId !== null && testId !== void 0 ? testId : 'ToolUse',
        style: style
    });
    return wrapSSR(/*#__PURE__*/ React.createElement("div", {
        className: containerClassName,
        "data-testid": testId !== null && testId !== void 0 ? testId : 'ToolUse',
        style: style
    }, toolItems));
};
// 使用 memo 优化组件，避免不必要的重新渲染
export var ToolUseBar = /*#__PURE__*/ memo(ToolUseBarComponent);
