import { useState, useEffect, useRef, useCallback } from "react"; interface CommentDialogProps { open: boolean; onClose: () => void; onSubmit: (text: string) => void; } export function CommentDialog({ open, onClose, onSubmit }: CommentDialogProps) { const [text, setText] = useState(""); const dialogRef = useRef(null); const inputRef = useRef(null); useEffect(() => { const dialog = dialogRef.current; if (!dialog) return; if (open && !dialog.open) { dialog.showModal(); setText(""); setTimeout(() => inputRef.current?.focus(), 50); } else if (!open && dialog.open) { dialog.close(); } }, [open]); const handleClose = useCallback(() => { dialogRef.current?.close(); onClose(); }, [onClose]); useEffect(() => { const dialog = dialogRef.current; if (!dialog) return; const onCancel = () => onClose(); dialog.addEventListener("close", onCancel); return () => dialog.removeEventListener("close", onCancel); }, [onClose]); const handleSubmit = () => { if (!text.trim()) return; onSubmit(text.trim()); setText(""); handleClose(); }; return (