import { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useWhiteboardStrokes } from '../hooks/useWhiteboardStrokes'; import { XIcon } from './icons'; import { WhiteboardCanvas, type WhiteboardColor, type WhiteboardTool, type WhiteboardWidth, } from './WhiteboardCanvas'; interface Props { whiteboardId: string; onClose: () => void; } const COLORS: WhiteboardColor[] = ['#000000', '#ef4444', '#3b82f6', '#22c55e', '#facc15', '#a855f7']; const WIDTHS: WhiteboardWidth[] = [2, 4, 8]; export function WhiteboardModal({ whiteboardId, onClose }: Props) { const { t } = useTranslation(); const { strokes, loading, error, insertStroke, clearAll } = useWhiteboardStrokes(whiteboardId); const [tool, setTool] = useState('pen'); const [color, setColor] = useState('#000000'); const [width, setWidth] = useState(4); const [confirmClear, setConfirmClear] = useState(false); useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [onClose]); const handleConfirmClear = async () => { setConfirmClear(false); try { await clearAll(); } catch (err) { console.error('clearAll failed', err); } }; return (

{t('app:whiteboard.title', { defaultValue: 'Whiteboard' })}

{loading ? (

{t('app:whiteboard.loading', { defaultValue: 'Lädt…' })}

) : error ? (

{t('app:whiteboard.error', { defaultValue: 'Whiteboard konnte nicht geladen werden.' })}

) : ( void insertStroke(payload)} whiteboardId={whiteboardId} /> )}
); }