import React, { useMemo, useContext } from 'react'; import cls from 'classnames'; import { IChatAnywhereConfigOnUpload } from '@agentscope-ai/chat/ChatAnywhere/hooks/types'; import { Attachments, Sender, useProviderContext } from '@agentscope-ai/chat'; import { SendHeaderContext } from '@agentscope-ai/chat/Sender/SenderHeader'; import MediaUpload from '../Upload'; import MediaInfo from '../Info'; import { GetProp } from 'antd'; import Style from './style'; type AttachedFiles = GetProp; export interface SenderHeaderProps { className?: string; onUpload?: IChatAnywhereConfigOnUpload[]; attachedFiles?: AttachedFiles[]; onFileChange?: (index: number, fileList: AttachedFiles) => void; } const SenderHeader: React.FC = (props) => { const { className, onUpload = [], attachedFiles = [[]], onFileChange } = props; const { getPrefixCls } = useProviderContext(); const { focus, enableFocusExpand } = useContext(SendHeaderContext); const prefixCls = getPrefixCls('aigc-sender-header'); const open = useMemo(() => { if (attachedFiles.flat().length > 0) { return true; } if (onUpload.length <= 0) { return false; } if (focus) { return true; } if (!enableFocusExpand) { return true; } return false; }, [onUpload, attachedFiles, enableFocusExpand, focus]); return ( <>