import { Prompt } from '@/types/prompt'; import { FC, KeyboardEvent, useEffect, useRef, useState } from 'react'; import { useTranslation } from 'next-i18next'; interface Props { prompt: Prompt; onClose: () => void; onUpdatePrompt: (prompt: Prompt) => void; } export const PromptModal: FC = ({ prompt, onClose, onUpdatePrompt }) => { const { t } = useTranslation('promptbar'); const [name, setName] = useState(prompt.name); const [description, setDescription] = useState(prompt.description); const [content, setContent] = useState(prompt.content); const modalRef = useRef(null); const nameInputRef = useRef(null); const handleEnter = (e: KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { onUpdatePrompt({ ...prompt, name, description, content: content.trim() }); onClose(); } }; useEffect(() => { const handleOutsideClick = (e: MouseEvent) => { if (modalRef.current && !modalRef.current.contains(e.target as Node)) { onClose(); } }; window.addEventListener('click', handleOutsideClick); return () => { window.removeEventListener('click', handleOutsideClick); }; }, [onClose]); useEffect(() => { nameInputRef.current?.focus(); }, []); return (