function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
    try {
        var info = gen[key](arg);
        var value = info.value;
    } catch (error) {
        reject(error);
        return;
    }
    if (info.done) {
        resolve(value);
    } else {
        Promise.resolve(value).then(_next, _throw);
    }
}
function _async_to_generator(fn) {
    return function() {
        var self = this, args = arguments;
        return new Promise(function(resolve, reject) {
            var gen = fn.apply(self, args);
            function _next(value) {
                asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
            }
            function _throw(err) {
                asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
            }
            _next(undefined);
        });
    };
}
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;
}
function _ts_generator(thisArg, body) {
    var f, y, t, _ = {
        label: 0,
        sent: function() {
            if (t[0] & 1) throw t[1];
            return t[1];
        },
        trys: [],
        ops: []
    }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
    return d(g, "next", {
        value: verb(0)
    }), d(g, "throw", {
        value: verb(1)
    }), d(g, "return", {
        value: verb(2)
    }), typeof Symbol === "function" && d(g, Symbol.iterator, {
        value: function() {
            return this;
        }
    }), g;
    function verb(n) {
        return function(v) {
            return step([
                n,
                v
            ]);
        };
    }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while(g && (g = 0, op[0] && (_ = 0)), _)try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [
                op[0] & 2,
                t.value
            ];
            switch(op[0]){
                case 0:
                case 1:
                    t = op;
                    break;
                case 4:
                    _.label++;
                    return {
                        value: op[1],
                        done: false
                    };
                case 5:
                    _.label++;
                    y = op[1];
                    op = [
                        0
                    ];
                    continue;
                case 7:
                    op = _.ops.pop();
                    _.trys.pop();
                    continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
                        _ = 0;
                        continue;
                    }
                    if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
                        _.label = op[1];
                        break;
                    }
                    if (op[0] === 6 && _.label < t[1]) {
                        _.label = t[1];
                        t = op;
                        break;
                    }
                    if (t && _.label < t[2]) {
                        _.label = t[2];
                        _.ops.push(op);
                        break;
                    }
                    if (t[2]) _.ops.pop();
                    _.trys.pop();
                    continue;
            }
            op = body.call(thisArg, _);
        } catch (e) {
            op = [
                6,
                e
            ];
            y = 0;
        } finally{
            f = t = 0;
        }
        if (op[0] & 5) throw op[1];
        return {
            value: op[0] ? op[1] : void 0,
            done: true
        };
    }
}
import { memo } from "react";
import { CheckCircleFilled } from "@ant-design/icons";
import { isFunction } from "lodash-es";
import React from "react";
import { ActionIconBox } from "../../../Components/ActionIconBox";
import { useCopied } from "../../../Hooks/useCopied";
import { useLocale } from "../../../I18n";
/**
 * CopyIcon 组件 - 复制图标组件
 *
 * 该组件显示一个复制图标，支持自定义 SVG 属性。
 * 主要用于表示复制功能的 UI 元素。
 *
 * @component
 * @description 复制图标组件，支持自定义 SVG 属性
 * @param {React.JSX.IntrinsicAttributes & React.SVGProps<SVGSVGElement>} props - SVG 属性
 *
 * @example
 * ```tsx
 * import { CopyIcon } from './CopyButton';
 *
 * // 基本用法
 * <CopyIcon />
 *
 * // 自定义样式
 * <CopyIcon className="custom-icon" />
 * ```
 *
 * @returns {React.ReactElement} 渲染的复制图标组件
 *
 * @remarks
 * - 使用 1em x 1em 的尺寸
 * - 支持所有标准的 SVG 属性
 * - 使用 14x14 的 viewBox
 * - 使用 currentColor 继承父元素颜色
 * - 包含 data-testid="copy-icon" 用于测试
 */ export var CopyIcon = function CopyIcon(props) {
    return /*#__PURE__*/ React.createElement("svg", _object_spread_props(_object_spread({}, props), {
        xmlns: "http://www.w3.org/2000/svg",
        xmlnsXlink: "http://www.w3.org/1999/xlink",
        fill: "none",
        version: "1.1",
        width: "1em",
        height: "1em",
        viewBox: "0 0 14.087890625 14.66650390625",
        "data-testid": "copy-icon"
    }), /*#__PURE__*/ React.createElement("g", null, /*#__PURE__*/ React.createElement("path", {
        d: "M10.8199,0.195262C10.6771,0.0702379,10.4834,0,10.2815,0L4.95203,0C3.69058,0,2.66797,0.895431,2.66797,2L2.66797,10C2.66797,11.1046,3.69058,12,4.95203,12L11.8042,12C13.0657,12,14.0883,11.1046,14.0883,10L14.0883,3.33333C14.0883,3.15652,14.0081,2.98695,13.8653,2.86193L10.8199,0.195262ZM10.2841,3.33333L12.0595,3.33333L9.7745,1.33252L9.52271,1.33255L9.52271,2.66667C9.52271,3.03486,9.86358,3.33333,10.2841,3.33333ZM4.76136,1.33319L8,1.33276L8,2.66667C8,3.77124,9.02261,4.66667,10.2841,4.66667L12.374,4.66667L12.3749,9.99985C12.3749,10.368,12.034,10.6665,11.6136,10.6665L4.76136,10.6665C4.34087,10.6665,4,10.368,4,9.99985L4,1.99985C4,1.63166,4.34087,1.33319,4.76136,1.33319ZM1.33333,4.40006C1.33333,4.03188,1.03486,3.7334,0.666667,3.7334C0.298477,3.7334,0,4.03188,0,4.40006L0,12.9334C0,13.8907,0.77604,14.6667,1.73333,14.6667L8.26667,14.6667C8.63486,14.6667,8.93333,14.3683,8.93333,14.0001C8.93333,13.6319,8.63486,13.3334,8.26667,13.3334L1.73333,13.3334C1.51242,13.3334,1.33333,13.1543,1.33333,12.9334L1.33333,4.40006Z",
        fillRule: "evenodd",
        fill: "currentColor",
        fillOpacity: 1
    })));
};
/**
 * CopyButton 组件 - 复制按钮组件
 *
 * 该组件提供一个可点击的复制按钮，支持复制功能和状态反馈。
 * 主要用于复制文本内容，并提供复制成功的视觉反馈。
 *
 * @component
 * @description 复制按钮组件，支持复制功能和状态反馈
 * @param {CopyButtonProps} props - 组件属性
 * @param {string} [props.className] - 自定义CSS类名
 * @param {Function} [props.onClick] - 点击事件回调
 * @param {React.ReactNode} [props.children] - 自定义子元素
 * @param {string} [props['data-testid']] - 测试标识符
 * @param {ActionIconBoxProps} props - 其他 ActionIconBox 属性
 *
 * @example
 * ```tsx
 * import { CopyButton } from './CopyButton';
 *
 * // 基本用法
 * <CopyButton onClick={() => copyText('Hello World')} />
 *
 * // 自定义图标
 * <CopyButton onClick={handleCopy}>
 *   <CustomIcon />
 * </CopyButton>
 * ```
 *
 * @returns {React.ReactElement} 渲染的复制按钮组件
 *
 * @remarks
 * - 使用 memo 进行性能优化
 * - 集成 useCopied hook 管理复制状态
 * - 点击时自动触发复制成功状态
 * - 支持自定义图标和样式
 * - 提供复制成功的视觉反馈
 */ export var CopyButton = /*#__PURE__*/ memo(function(_0) {
    var className = _0.className, onClick = _0.onClick, dataTestId = _0['data-testid'], props = _object_without_properties(_0, [
        "className",
        "onClick",
        'data-testid'
    ]);
    var _useCopied = useCopied(), copied = _useCopied.copied, setCopied = _useCopied.setCopied;
    var locale = useLocale();
    var copySuccessText = (locale === null || locale === void 0 ? void 0 : locale['chat.message.copy.success']) || '复制成功';
    return /*#__PURE__*/ React.createElement(ActionIconBox, _object_spread_props(_object_spread({
        onClick: function onClick1(e) {
            return _async_to_generator(function() {
                return _ts_generator(this, function(_state) {
                    switch(_state.label){
                        case 0:
                            return [
                                4,
                                onClick === null || onClick === void 0 ? void 0 : onClick(e)
                            ];
                        case 1:
                            _state.sent();
                            setCopied();
                            return [
                                2
                            ];
                    }
                });
            })();
        }
    }, props), {
        "data-testid": dataTestId,
        title: copied ? /*#__PURE__*/ React.createElement("span", {
            style: {
                display: 'flex',
                alignItems: 'center',
                gap: 4
            }
        }, /*#__PURE__*/ React.createElement(CheckCircleFilled, {
            style: {
                color: '#52c41a'
            }
        }), copySuccessText) : props.title
    }), function(isHovered) {
        return props.children ? isFunction(props.children) ? props.children(isHovered) : props.children : /*#__PURE__*/ React.createElement(CopyIcon, {
            className: className
        });
    });
});
