import React, { useEffect, useRef, useState } from 'react' import type { FieldProps } from './field-types' const LongTextField: React.FC> = ({ value, onSave, readOnly }) => { const [isEditing, setIsEditing] = useState(false) const [localValue, setLocalValue] = useState(value || '') const textareaRef = useRef(null) const containerRef = useRef(null) const [expanded, setExpanded] = useState(false) useEffect(() => { setLocalValue(value || '') }, [value]) useEffect(() => { if (isEditing && textareaRef.current) { textareaRef.current.focus() setExpanded(false) } }, [isEditing]) // Handle click outside to close expanded state useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if ( expanded && containerRef.current && !containerRef.current.contains(event.target as Node) ) { setExpanded(false) } } if (expanded) { document.addEventListener('mousedown', handleClickOutside) } return () => { document.removeEventListener('mousedown', handleClickOutside) } }, [expanded]) const handleBlur = () => { setIsEditing(false) onSave(localValue) } const handlePlaceholderClick = (e: React.MouseEvent) => { e.stopPropagation() setExpanded(true) } const handleOverlayClick = (e: React.MouseEvent) => { e.stopPropagation() if (!readOnly) { setIsEditing(true) } } if (isEditing) { return (