import { memo, useState, useRef, useEffect } from 'react' import { Send, X, Pencil, Loader2 } from 'lucide-react' import { useRefreshMessage } from '@/hooks/useRemoveMessage' interface EditableUserMessageProps { opcodeUrl: string sessionId: string directory?: string content: string assistantMessageId: string onCancel: () => void model?: string agent?: string } export const EditableUserMessage = memo(function EditableUserMessage({ opcodeUrl, sessionId, directory, content, assistantMessageId, onCancel, model, agent }: EditableUserMessageProps) { const [editedContent, setEditedContent] = useState(content) const textareaRef = useRef(null) const refreshMessage = useRefreshMessage({ opcodeUrl, sessionId, directory }) useEffect(() => { if (textareaRef.current) { textareaRef.current.focus() textareaRef.current.setSelectionRange( textareaRef.current.value.length, textareaRef.current.value.length ) } }, []) useEffect(() => { if (textareaRef.current) { textareaRef.current.style.height = 'auto' textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px` } }, [editedContent]) const handleSubmit = () => { if (!editedContent.trim() || refreshMessage.isPending) return refreshMessage.mutate({ assistantMessageID: assistantMessageId, userMessageContent: editedContent.trim(), model, agent }, { onSuccess: () => { onCancel() } }) } const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) { e.preventDefault() handleSubmit() } else if (e.key === 'Escape') { e.preventDefault() onCancel() } } return (