import type { FC } from 'react' import { memo, useCallback, useRef, useState } from 'react' import Textarea from 'react-textarea-autosize' import { RiSendPlane2Fill } from '@remixicon/react' import cn from '@/utils/classnames' import Button from '@/app/components/base/button' import Avatar from '@/app/components/base/avatar' import { useAppContext } from '@/context/app-context' type CommentInputProps = { position: { x: number; y: number } onSubmit: (content: string) => void onCancel: () => void } export const CommentInput: FC = memo(({ position, onSubmit, onCancel }) => { const [content, setContent] = useState('') const textareaRef = useRef(null) const { userProfile } = useAppContext() const handleSubmit = useCallback(() => { try { if (content.trim()) { onSubmit(content.trim()) setContent('') } } catch (error) { console.error('Error in CommentInput handleSubmit:', error) } }, [content, onSubmit]) const handleKeyDown = useCallback((e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault() handleSubmit() } else if (e.key === 'Escape') { onCancel() } }, [handleSubmit, onCancel]) return (