import React, { useEffect, useRef, useState } from 'react'; import { ArrowUp, Pencil, X } from 'lucide-react'; import useRenderTracker from '../../../hooks/useRenderTracker'; import MessageAttachments, { type MessageAttachment } from '../MessageAttachments'; interface UserMessageProps { content: string; messageId?: string; isLatestEditable?: boolean; onEditAndResubmit?: (messageId: string, text: string) => void; attachments?: MessageAttachment[]; } const UserMessage = ({ content, messageId, isLatestEditable, onEditAndResubmit, attachments }: UserMessageProps) => { useRenderTracker('UserMessage', { content }); const canEdit = Boolean(messageId) && Boolean(isLatestEditable); const [isEditing, setIsEditing] = useState(false); const [draft, setDraft] = useState(content); const editRef = useRef(null); useEffect(() => { if (isEditing) { setDraft(content); const el = editRef.current; if (el) { el.style.height = 'auto'; el.style.height = `${el.scrollHeight}px`; el.focus(); el.setSelectionRange(el.value.length, el.value.length); } } }, [isEditing, content]); const save = () => { const trimmed = draft.trim(); if (trimmed && messageId) { onEditAndResubmit?.(messageId, trimmed); } setIsEditing(false); }; if (isEditing) { return (