'use client' import { useCallback, useEffect, useState } from 'react' import { useGridEditor } from './useGridEditor' import type { GridZone } from './types' import { GridToolbar } from './GridToolbar' import { GridTable } from './GridTable' import { GridImageOverlay } from './GridImageOverlay' interface GridEditorProps { sessionId: string | null onNext?: () => void } export function GridEditor({ sessionId, onNext }: GridEditorProps) { const { grid, loading, saving, error, dirty, selectedCell, setSelectedCell, buildGrid, loadGrid, saveGrid, updateCellText, toggleColumnBold, toggleRowHeader, undo, redo, canUndo, canRedo, getAdjacentCell, deleteColumn, addColumn, deleteRow, addRow, ipaMode, setIpaMode, syllableMode, setSyllableMode, } = useGridEditor(sessionId) const [showOverlay, setShowOverlay] = useState(false) // Load grid on mount useEffect(() => { if (sessionId) { loadGrid() } }, [sessionId, loadGrid]) // Keyboard shortcuts useEffect(() => { const handler = (e: KeyboardEvent) => { if ((e.metaKey || e.ctrlKey) && e.key === 'z' && !e.shiftKey) { e.preventDefault() undo() } else if ((e.metaKey || e.ctrlKey) && e.key === 'z' && e.shiftKey) { e.preventDefault() redo() } else if ((e.metaKey || e.ctrlKey) && e.key === 's') { e.preventDefault() saveGrid() } } window.addEventListener('keydown', handler) return () => window.removeEventListener('keydown', handler) }, [undo, redo, saveGrid]) const handleNavigate = useCallback( (cellId: string, direction: 'up' | 'down' | 'left' | 'right') => { const target = getAdjacentCell(cellId, direction) if (target) { setSelectedCell(target) // Focus the input setTimeout(() => { const el = document.getElementById(`cell-${target}`) if (el) { el.focus() if (el instanceof HTMLInputElement) el.select() } }, 0) } }, [getAdjacentCell, setSelectedCell], ) if (!sessionId) { return (
Fehler: {error}
Kein Grid vorhanden.