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;
}
import { ConfigProvider, Tooltip, theme as antdTheme } from "antd";
import classNames from "clsx";
import React, { useContext, useEffect, useMemo } from "react";
import { ErrorBoundary } from "react-error-boundary";
import { STOP_ICON_DISK_FILL, STOP_ICON_HALO_FILL, StopIcon } from "../../AgentRunBar/icons";
import { I18nContext } from "../../I18n";
import { getSendButtonPalette, resolveSendButtonDisplayColors } from "./sendButtonPalette";
import { useStyle } from "./style";
/**
 * 解析发送按钮的最终禁用状态：用户显式传入优先，否则按上传状态判断
 */ export function resolveSendDisabled(sendButtonProps, fileUploadStatus) {
    var _ref;
    return (_ref = sendButtonProps === null || sendButtonProps === void 0 ? void 0 : sendButtonProps.disabled) !== null && _ref !== void 0 ? _ref : fileUploadStatus === 'uploading';
}
function SendIcon(props) {
    var isActive = props.isActive, disabled = props.disabled, typing = props.typing, displayColors = props.displayColors, rest = _object_without_properties(props, [
        "isActive",
        "disabled",
        "typing",
        "displayColors"
    ]);
    if (typing) {
        return /*#__PURE__*/ React.createElement(StopIcon, _object_spread_props(_object_spread({}, rest), {
            diskFill: STOP_ICON_DISK_FILL,
            haloFill: STOP_ICON_HALO_FILL
        }));
    }
    var useActive = isActive && !disabled;
    var circleFill = useActive ? displayColors.backgroundActive : displayColors.backgroundMuted;
    var arrowFill = useActive ? displayColors.iconActive : displayColors.iconMuted;
    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("circle", {
        cx: "50%",
        cy: "50%",
        r: "0.5em",
        fill: circleFill,
        fillOpacity: 1,
        style: {
            transition: 'fill 0.6s ease-in-out, fill-opacity 0.6s ease-in-out'
        }
    }), /*#__PURE__*/ React.createElement("g", null, /*#__PURE__*/ React.createElement("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",
        fill: arrowFill,
        fillOpacity: 1,
        style: {
            transition: 'fill 0.2s ease-in-out, fill-opacity 0.2s ease-in-out'
        }
    })));
}
/**
 * SendButton 组件 - 发送按钮组件
 *
 * 该组件提供一个可点击的发送按钮，根据不同状态（悬停、禁用、输入中）
 * 呈现不同的视觉效果和动画。支持紧凑模式和自定义样式。
 *
 * @component
 * @description 发送按钮组件，支持多种状态和动画效果
 * @param {SendButtonProps} props - 组件属性
 * @param {boolean} props.isSendable - 是否处于可发送状态
 * @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
 *   isSendable
 *   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 _ref, _ref1;
    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);
    // 仅在挂载时触发一次，避免引用变化导致重复打点
    // eslint-disable-next-line react-hooks/exhaustive-deps -- onInit intentionally once on mount
    }, []);
    var token = antdTheme.useToken().token;
    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;
    var displayColors = useMemo(function() {
        return resolveSendButtonDisplayColors(getSendButtonPalette({
            colorPrimary: token.colorPrimary,
            colorBgContainer: token.colorBgContainer,
            colorTextLightSolid: token.colorTextLightSolid,
            colorTextTertiary: token.colorTextTertiary,
            colorFillTertiary: token.colorFillTertiary,
            colorText: token.colorText
        }), colors, {
            colorPrimary: token.colorPrimary,
            colorBgContainer: token.colorBgContainer,
            colorTextLightSolid: token.colorTextLightSolid,
            colorTextTertiary: token.colorTextTertiary,
            colorFillTertiary: token.colorFillTertiary,
            colorText: token.colorText
        });
    }, [
        colors,
        token.colorBgContainer,
        token.colorFillTertiary,
        token.colorPrimary,
        token.colorText,
        token.colorTextLightSolid,
        token.colorTextTertiary
    ]);
    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 ariaLabelSend = (_ref = locale === null || locale === void 0 ? void 0 : locale['input.sendButtonAriaLabel.send']) !== null && _ref !== void 0 ? _ref : '发送消息';
    var ariaLabelStop = (_ref1 = locale === null || locale === void 0 ? void 0 : locale['input.sendButtonAriaLabel.stop']) !== null && _ref1 !== void 0 ? _ref1 : '停止生成';
    var sendButtonAriaLabel = typing ? ariaLabelStop : ariaLabelSend;
    var _obj;
    return wrapSSR(/*#__PURE__*/ React.createElement(Tooltip, {
        arrow: false,
        title: tooltipTitle,
        mouseEnterDelay: 0.5
    }, /*#__PURE__*/ React.createElement("div", {
        "data-testid": "send-button",
        "aria-label": sendButtonAriaLabel,
        "aria-disabled": disabled ? true : undefined,
        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 || !isSendable), _define_property(_obj, "".concat(baseCls, "-typing"), typing), _obj))
    }, /*#__PURE__*/ React.createElement(ErrorBoundary, {
        fallback: /*#__PURE__*/ React.createElement("div", null)
    }, /*#__PURE__*/ React.createElement(SendIcon, {
        isActive: isSendable,
        disabled: disabled,
        typing: typing,
        displayColors: displayColors
    })))));
};
