import { useState, useRef, useEffect } from 'react'; interface EditableTextProps { value: string; onSave: (val: string) => void; className?: string; multiline?: boolean; placeholder?: string; } /** * 클릭하면 편집 가능한 텍스트 컴포넌트 * - 클릭 → 입력 필드로 전환 * - Enter 또는 blur → 저장 * - Escape → 취소 */ export function EditableText({ value, onSave, className = '', multiline = false, placeholder = '클릭하여 입력' }: EditableTextProps) { const [editing, setEditing] = useState(false); const [draft, setDraft] = useState(value); const inputRef = useRef(null); useEffect(() => { setDraft(value); }, [value]); useEffect(() => { if (editing) inputRef.current?.focus(); }, [editing]); const commit = () => { setEditing(false); if (draft.trim() !== value) onSave(draft.trim()); }; const cancel = () => { setEditing(false); setDraft(value); }; const sharedClass = `w-full bg-white/90 border-b-2 border-blue-400 outline-none rounded px-1 resize-none ${className}`; if (editing) { return multiline ? (