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 React, { useMemo } from "react";
import { AttachmentFileList } from "../AttachmentButton/AttachmentFileList";
import { SendActions } from "../SendActions";
/**
 * 附件列表渲染 Hook
 */ export var useAttachmentList = function(param) {
    var attachment = param.attachment, fileMap = param.fileMap, handleFileRemoval = param.handleFileRemoval, handleFileRetry = param.handleFileRetry, updateAttachmentFiles = param.updateAttachmentFiles;
    return useMemo(function() {
        if (!(attachment === null || attachment === void 0 ? void 0 : attachment.enable)) return null;
        return React.createElement(AttachmentFileList, {
            fileMap: fileMap,
            onDelete: handleFileRemoval,
            onRetry: handleFileRetry,
            onClearFileMap: function() {
                updateAttachmentFiles(undefined);
            }
        });
    }, [
        attachment === null || attachment === void 0 ? void 0 : attachment.enable,
        fileMap,
        handleFileRemoval,
        handleFileRetry,
        updateAttachmentFiles
    ]);
};
/**
 * BeforeTools 渲染 Hook
 */ export var useBeforeTools = function(param) {
    var beforeToolsRender = param.beforeToolsRender, props = param.props, isHover = param.isHover, isLoading = param.isLoading;
    return useMemo(function() {
        if (beforeToolsRender) {
            return beforeToolsRender(_object_spread_props(_object_spread({}, props), {
                isHover: isHover,
                isLoading: isLoading
            }));
        }
        return null;
    }, [
        beforeToolsRender,
        props,
        isHover,
        isLoading
    ]);
};
/**
 * SendActions 节点渲染 Hook
 */ export var useSendActionsNode = function(param) {
    var sendProps = param.props, fileMap = param.fileMap, setFileMap = param.setFileMap, supportedFormat = param.supportedFormat, fileUploadDone = param.fileUploadDone, recording = param.recording, isLoading = param.isLoading, collapseSendActions = param.collapseSendActions, uploadImage = param.uploadImage, startRecording = param.startRecording, stopRecording = param.stopRecording, sendMessage = param.sendMessage, setIsLoading = param.setIsLoading, onStop = param.onStop, setRightPadding = param.setRightPadding, baseCls = param.baseCls, hashId = param.hashId;
    return useMemo(function() {
        var _sendProps_attachment;
        return React.createElement(SendActions, {
            attachment: _object_spread_props(_object_spread({}, sendProps.attachment), {
                supportedFormat: supportedFormat,
                fileMap: fileMap,
                onFileMapChange: setFileMap,
                upload: ((_sendProps_attachment = sendProps.attachment) === null || _sendProps_attachment === void 0 ? void 0 : _sendProps_attachment.upload) ? function(file) {
                    return sendProps.attachment.upload(file, 0);
                } : undefined
            }),
            voiceRecognizer: sendProps.voiceRecognizer,
            value: sendProps.value,
            disabled: sendProps.disabled,
            typing: sendProps.typing,
            isLoading: isLoading,
            fileUploadDone: fileUploadDone,
            recording: recording,
            collapseSendActions: collapseSendActions,
            allowEmptySubmit: sendProps.allowEmptySubmit,
            uploadImage: uploadImage,
            onStartRecording: startRecording,
            onStopRecording: stopRecording,
            onSend: sendMessage,
            onStop: function() {
                setIsLoading(false);
                onStop === null || onStop === void 0 ? void 0 : onStop();
            },
            actionsRender: sendProps.actionsRender,
            prefixCls: baseCls,
            hashId: hashId,
            hasTools: !!sendProps.toolsRender,
            onResize: setRightPadding,
            sendButtonProps: sendProps.sendButtonProps
        });
    }, [
        sendProps.attachment,
        sendProps.voiceRecognizer,
        sendProps.value,
        sendProps.disabled,
        sendProps.typing,
        sendProps.allowEmptySubmit,
        sendProps.actionsRender,
        sendProps.toolsRender,
        sendProps.sendButtonProps,
        fileMap,
        setFileMap,
        supportedFormat,
        fileUploadDone,
        recording,
        isLoading,
        collapseSendActions,
        uploadImage,
        startRecording,
        stopRecording,
        sendMessage,
        setIsLoading,
        onStop,
        setRightPadding,
        baseCls,
        hashId
    ]);
};
