import { useEffect, useRef } from 'react'; import Button from './ui/Button.jsx'; export default function PgnDialog({ explorer }) { const { pgnDialogOpen, pgnError, actions } = explorer; const textareaRef = useRef(null); useEffect(() => { if (pgnDialogOpen) textareaRef.current?.focus(); }, [pgnDialogOpen]); useEffect(() => { if (!pgnDialogOpen) return; function onKeydown(e) { if (e.key === 'Escape') { e.preventDefault(); actions.closePgnDialog(); } } document.addEventListener('keydown', onKeydown); return () => document.removeEventListener('keydown', onKeydown); }, [pgnDialogOpen, actions]); function onBackdropClick(e) { if (e.target.id === 'pgn-dialog') actions.closePgnDialog(); } function onParseClick() { actions.parsePgnAction(textareaRef.current?.value || ''); } return (