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 { ConfigProvider, Tooltip } from "antd";
import classNames from "clsx";
import { motion } from "framer-motion";
import React, { useContext, useEffect } from "react";
import { ErrorBoundary } from "react-error-boundary";
import { StopIcon } from "../../AgentRunBar/icons";
import { I18nContext } from "../../I18n";
import { useStyle } from "./style";
var DEFAULT_SEND_BUTTON_COLORS = {
    icon: '#00183D',
    iconHover: '#fff',
    background: '#001C39',
    backgroundHover: '#14161C'
};
function SendIcon(props) {
    var _ref, _ref1, _ref2, _ref3;
    var hover = props.hover, typing = props.typing, onInit = props.onInit, colors = props.colors, rest = _object_without_properties(props, [
        "hover",
        "typing",
        "onInit",
        "colors"
    ]);
    useEffect(function() {
        onInit === null || onInit === void 0 ? void 0 : onInit();
    }, []);
    if (typing) {
        return /*#__PURE__*/ React.createElement(StopIcon, rest);
    }
    var currentColors = {
        icon: (_ref = colors === null || colors === void 0 ? void 0 : colors.icon) !== null && _ref !== void 0 ? _ref : DEFAULT_SEND_BUTTON_COLORS.icon,
        iconHover: (_ref1 = colors === null || colors === void 0 ? void 0 : colors.iconHover) !== null && _ref1 !== void 0 ? _ref1 : DEFAULT_SEND_BUTTON_COLORS.iconHover,
        background: (_ref2 = colors === null || colors === void 0 ? void 0 : colors.background) !== null && _ref2 !== void 0 ? _ref2 : DEFAULT_SEND_BUTTON_COLORS.background,
        backgroundHover: (_ref3 = colors === null || colors === void 0 ? void 0 : colors.backgroundHover) !== null && _ref3 !== void 0 ? _ref3 : DEFAULT_SEND_BUTTON_COLORS.backgroundHover
    };
    return /*#__PURE__*/ React.createElement("svg", _object_spread({
        xmlns: "http://www.w3.org/2000/svg",
        fill: "none",
        width: "1em",
        height: "1em",
        viewBox: "0 0 32 32"
    }, rest), /*#__PURE__*/ React.createElement(motion.circle, {
        cx: "50%",
        cy: "50%",
        r: "0.5em",
        initial: false,
        animate: {
            fill: hover ? currentColors.backgroundHover : currentColors.background,
            fillOpacity: hover ? 1 : 0.03530000150203705
        },
        transition: {
            duration: 0.6,
            ease: 'easeInOut'
        }
    }), /*#__PURE__*/ React.createElement("g", null, /*#__PURE__*/ React.createElement(motion.path, {
        d: "M16.667 12.943l3.528 3.528a.667.667 0 00.943-.942l-4.666-4.667a.665.665 0 00-.943 0l-4.667 4.667a.667.667 0 10.943.942l3.528-3.528v7.724a.667.667 0 101.334 0v-7.724z",
        fillRule: "evenodd",
        initial: false,
        animate: {
            fill: hover ? currentColors.iconHover : currentColors.icon,
            fillOpacity: hover ? 1 : 0.24709999561309814
        },
        transition: {
            duration: 0.2,
            ease: 'easeInOut'
        }
    })));
}
/**
 * SendButton 组件 - 发送按钮组件
 *
 * 该组件提供一个可点击的发送按钮，根据不同状态（悬停、禁用、输入中）
 * 呈现不同的视觉效果和动画。支持紧凑模式和自定义样式。
 *
 * @component
 * @description 发送按钮组件，支持多种状态和动画效果
 * @param {SendButtonProps} props - 组件属性
 * @param {boolean} props.isHover - 指示鼠标是否悬停在按钮上
 * @param {boolean} props.disabled - 指示按钮是否禁用
 * @param {boolean} props.typing - 指示是否处于输入状态
 * @param {() => void} props.onClick - 点击按钮时的回调函数
 * @param {React.CSSProperties} [props.style] - 应用于按钮容器的自定义样式
 * @param {() => void} [props.onInit] - 组件初始化时调用的可选回调函数
 * @param {boolean} [props.compact] - 是否使用紧凑模式样式
 * @param {SendButtonColors} [props.colors] - 自定义按钮颜色
 *
 * @example
 * ```tsx
 * <SendButton
 *   isHover={false}
 *   disabled={false}
 *   typing={false}
 *   onClick={() => console.log('发送消息')}
 *   compact={false}
 *   colors={{
 *     icon: '#666',
 *     iconHover: '#fff',
 *     background: '#f0f0f0',
 *     backgroundHover: '#1890ff'
 *   }}
 * />
 * ```
 *
 * @returns {React.ReactElement|null} 渲染的发送按钮组件，SSR环境下返回null
 *
 * @remarks
 * - 支持悬停、禁用、输入中等多种状态
 * - 提供流畅的动画效果
 * - 支持紧凑模式显示
 * - 支持自定义颜色配置
 * - 在SSR环境下不渲染
 */ export var SendButton = function SendButton(props) {
    var isSendable = props.isSendable, disabled = props.disabled, typing = props.typing, onClick = props.onClick, style = props.style, colors = props.colors, _props_triggerSendKey = props.triggerSendKey, triggerSendKey = _props_triggerSendKey === void 0 ? 'Enter' : _props_triggerSendKey;
    useEffect(function() {
        var _props_onInit;
        (_props_onInit = props.onInit) === null || _props_onInit === void 0 ? void 0 : _props_onInit.call(props);
    }, []);
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var locale = useContext(I18nContext).locale;
    var baseCls = getPrefixCls('agentic-md-input-field-send-button');
    var _useStyle = useStyle(baseCls), wrapSSR = _useStyle.wrapSSR, hashId = _useStyle.hashId;
    if (typeof window === 'undefined' || typeof document === 'undefined' || !window.document) {
        // SSR 环境下不渲染
        return null;
    }
    var sendText = (triggerSendKey === 'Mod+Enter' ? locale === null || locale === void 0 ? void 0 : locale['input.sendButtonTooltip.send.mod'] : locale === null || locale === void 0 ? void 0 : locale['input.sendButtonTooltip.send']) || (triggerSendKey === 'Mod+Enter' ? '按 Cmd/Ctrl+Enter 键发送' : '按 Enter 键发送');
    var newlineText = (triggerSendKey === 'Mod+Enter' ? locale === null || locale === void 0 ? void 0 : locale['input.sendButtonTooltip.newline.mod'] : locale === null || locale === void 0 ? void 0 : locale['input.sendButtonTooltip.newline']) || (triggerSendKey === 'Mod+Enter' ? '按 Enter 键换行' : '按 Shift+Enter 键换行');
    var tooltipTitle = /*#__PURE__*/ React.createElement("div", {
        style: {
            lineHeight: '1.5',
            textAlign: 'left'
        }
    }, /*#__PURE__*/ React.createElement("div", null, sendText), /*#__PURE__*/ React.createElement("div", null, newlineText));
    var _obj;
    return wrapSSR(/*#__PURE__*/ React.createElement(Tooltip, {
        arrow: false,
        title: tooltipTitle,
        mouseEnterDelay: 0.5
    }, /*#__PURE__*/ React.createElement("div", {
        "data-testid": "send-button",
        onClick: function onClick1() {
            if (!disabled) {
                onClick();
            }
        },
        role: "button",
        tabIndex: 0,
        onKeyDown: function onKeyDown(e) {
            if (disabled) return;
            if (e.key === 'Enter' || e.key === ' ') {
                e.preventDefault(); // 防止键盘事件触发 click 事件
                onClick();
            }
        },
        style: style,
        className: classNames(baseCls, hashId, (_obj = {}, _define_property(_obj, "".concat(baseCls, "-compact"), props.compact), _define_property(_obj, "".concat(baseCls, "-disabled"), disabled), _define_property(_obj, "".concat(baseCls, "-typing"), typing), _obj))
    }, /*#__PURE__*/ React.createElement(ErrorBoundary, {
        fallback: /*#__PURE__*/ React.createElement("div", null)
    }, /*#__PURE__*/ React.createElement(SendIcon, {
        hover: isSendable && !disabled,
        disabled: disabled,
        typing: typing,
        colors: colors
    })))));
};
