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;
}
import { EllipsisVertical } from "@sofa-design/icons";
import { Popover } from "antd";
import classNames from "clsx";
import RcResizeObserver from "rc-resize-observer";
import React, { useContext, useMemo } from "react";
import { ActionIconBox } from "../../Components/ActionIconBox";
import { I18nContext } from "../../I18n";
import { AttachmentButton } from "../AttachmentButton";
import { SendButton } from "../SendButton";
import { VoiceInputButton } from "../VoiceInput";
/**
 * SendActions 组件 - 发送操作按钮区域
 *
 * @description 封装发送操作相关的按钮，包括附件上传、语音输入、发送按钮等
 */ export var SendActions = function SendActions(param) {
    var attachment = param.attachment, voiceRecognizer = param.voiceRecognizer, value = param.value, disabled = param.disabled, typing = param.typing, isLoading = param.isLoading, _param_fileUploadDone = param.fileUploadDone, fileUploadDone = _param_fileUploadDone === void 0 ? true : _param_fileUploadDone, _param_recording = param.recording, recording = _param_recording === void 0 ? false : _param_recording, _param_collapseSendActions = param.collapseSendActions, collapseSendActions = _param_collapseSendActions === void 0 ? false : _param_collapseSendActions, _param_allowEmptySubmit = param.allowEmptySubmit, allowEmptySubmit = _param_allowEmptySubmit === void 0 ? false : _param_allowEmptySubmit, uploadImage = param.uploadImage, onStartRecording = param.onStartRecording, onStopRecording = param.onStopRecording, onSend = param.onSend, onStop = param.onStop, actionsRender = param.actionsRender, _param_prefixCls = param.prefixCls, prefixCls = _param_prefixCls === void 0 ? 'ant-agentic-md-input-field' : _param_prefixCls, _param_hashId = param.hashId, hashId = _param_hashId === void 0 ? '' : _param_hashId, _param_hasTools = param.hasTools, hasTools = _param_hasTools === void 0 ? false : _param_hasTools, onResize = param.onResize, sendButtonProps = param.sendButtonProps, triggerSendKey = param.triggerSendKey;
    var fileMap = attachment === null || attachment === void 0 ? void 0 : attachment.fileMap;
    var defaultActionsLen = [
        (attachment === null || attachment === void 0 ? void 0 : attachment.enable) ? '()' : null,
        voiceRecognizer ? '()' : null,
        '()'
    ].filter(Boolean).length;
    var locale = useContext(I18nContext).locale;
    /**
   * 默认发送操作按钮
   */ var defaultActions = useMemo(function() {
        return [
            (attachment === null || attachment === void 0 ? void 0 : attachment.enable) ? /*#__PURE__*/ React.createElement(AttachmentButton, _object_spread_props(_object_spread({
                uploadImage: uploadImage || function() {
                    return Promise.resolve();
                },
                key: "attachment-button",
                title: collapseSendActions && defaultActionsLen > 2 ? (locale === null || locale === void 0 ? void 0 : locale['input.fileUpload']) || '文件上传' : ''
            }, attachment), {
                fileMap: fileMap,
                onFileMapChange: function onFileMapChange(fileMap) {
                    var _attachment_onFileMapChange;
                    attachment === null || attachment === void 0 ? void 0 : (_attachment_onFileMapChange = attachment.onFileMapChange) === null || _attachment_onFileMapChange === void 0 ? void 0 : _attachment_onFileMapChange.call(attachment, fileMap);
                },
                disabled: !fileUploadDone || (attachment === null || attachment === void 0 ? void 0 : attachment.disabled)
            })) : null,
            voiceRecognizer ? /*#__PURE__*/ React.createElement(VoiceInputButton, {
                key: "voice-input-button",
                title: collapseSendActions && defaultActionsLen > 2 ? (locale === null || locale === void 0 ? void 0 : locale['input.voiceInput']) || '语音输入' : '',
                recording: recording,
                disabled: disabled,
                onStart: onStartRecording || function() {
                    return Promise.resolve();
                },
                onStop: onStopRecording || function() {
                    return Promise.resolve();
                }
            }) : null,
            /*#__PURE__*/ React.createElement(SendButton, _object_spread({
                key: "send-button",
                typing: !!typing || !!isLoading,
                isSendable: allowEmptySubmit || !!(value === null || value === void 0 ? void 0 : value.trim()) || fileMap && fileMap.size > 0 || recording,
                disabled: disabled,
                onClick: function onClick() {
                    if (typing || isLoading) {
                        onStop === null || onStop === void 0 ? void 0 : onStop();
                        return;
                    }
                    onSend === null || onSend === void 0 ? void 0 : onSend();
                },
                triggerSendKey: triggerSendKey
            }, sendButtonProps))
        ].filter(Boolean);
    }, [
        attachment,
        fileUploadDone,
        value,
        collapseSendActions,
        isLoading,
        disabled,
        typing,
        recording,
        voiceRecognizer,
        allowEmptySubmit,
        uploadImage,
        onStartRecording,
        onStopRecording,
        onSend,
        onStop,
        fileMap,
        sendButtonProps,
        triggerSendKey
    ]);
    var actionsList = actionsRender ? actionsRender({
        attachment: attachment,
        voiceRecognizer: voiceRecognizer,
        value: value,
        disabled: disabled,
        typing: typing,
        isLoading: isLoading,
        fileUploadDone: fileUploadDone,
        recording: recording,
        collapseSendActions: collapseSendActions,
        allowEmptySubmit: allowEmptySubmit,
        uploadImage: uploadImage,
        onStartRecording: onStartRecording,
        onStopRecording: onStopRecording,
        onSend: onSend,
        onStop: onStop,
        fileUploadStatus: fileUploadDone ? 'done' : 'uploading'
    }, defaultActions) : defaultActions;
    return /*#__PURE__*/ React.createElement(RcResizeObserver, {
        onResize: function onResize1(e) {
            onResize === null || onResize === void 0 ? void 0 : onResize(e.offsetWidth);
        }
    }, /*#__PURE__*/ React.createElement("div", {
        contentEditable: false,
        onClick: function onClick(e) {
            e.stopPropagation();
            e.preventDefault();
        },
        onKeyDown: function onKeyDown(e) {
            e.stopPropagation();
            e.preventDefault();
        },
        className: classNames("".concat(prefixCls, "-send-actions"), _define_property({}, "".concat(prefixCls, "-send-has-tools"), hasTools), hashId)
    }, collapseSendActions && actionsList.length > 2 ? /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Popover, {
        trigger: "click",
        styles: {
            body: {
                padding: 4
            }
        },
        arrow: false,
        content: /*#__PURE__*/ React.createElement("div", {
            style: {
                width: 100,
                display: 'flex',
                flexDirection: 'column',
                gap: 8
            }
        }, actionsList === null || actionsList === void 0 ? void 0 : actionsList.filter(function(item) {
            if (/*#__PURE__*/ React.isValidElement(item) && (item === null || item === void 0 ? void 0 : item.key) === 'send-button') {
                return false;
            }
            return true;
        }))
    }, /*#__PURE__*/ React.createElement(ActionIconBox, {
        style: {
            fontSize: 16,
            color: 'var(--color-gray-text-secondary)'
        }
    }, /*#__PURE__*/ React.createElement(EllipsisVertical, null))), actionsList.find(function(item) {
        if (/*#__PURE__*/ React.isValidElement(item) && (item === null || item === void 0 ? void 0 : item.key) === 'send-button') {
            return true;
        }
        return false;
    })) : actionsList));
};
