import { useState, useEffect, useRef } from 'react' import DrawCanvas, { type DrawCanvasHandle } from '../components/DrawCanvas' import BlurhashCanvas from '../components/BlurhashCanvas' import Topbar from '../components/Topbar' import { getDbPictures, getDbObjects, getDbObjectPairs, createDbPair, directusAssetUrl, } from '../api' import { useAuth } from '../context/AuthContext' import type { DbPicture, DbObject, DbPair, CanvasObject } from '../types' const ChevronLeftIcon = () => ( ) const ChevronRightIcon = () => ( ) // ── PairForm ────────────────────────────────────────────────────────────────── interface PendingWord { titel_de: string level: number } interface PairFormProps { objectId: string token: string onSaved: () => void onCancel: () => void } function PairForm({ objectId, token, onSaved, onCancel }: PairFormProps) { const [level, setLevel] = useState(5) const [questionDe, setQuestionDe] = useState('') const [statementDe, setStatementDe] = useState('') const [words, setWords] = useState([]) const [wordInput, setWordInput] = useState('') const [wordLevel, setWordLevel] = useState(50) const [saving, setSaving] = useState(false) const [error, setError] = useState('') const wordInputRef = useRef(null) const addWord = () => { const t = wordInput.trim() if (!t || words.some(w => w.titel_de === t)) { setWordInput(''); return } setWords(prev => [...prev, { titel_de: t, level: wordLevel }]) setWordInput('') setWordLevel(50) wordInputRef.current?.focus() } const handleSave = async () => { if (!statementDe.trim()) { setError('Aussage (statement_de) ist Pflicht.'); return } setSaving(true) setError('') try { await createDbPair(objectId, { question_de: questionDe.trim() || undefined, statement_de: statementDe.trim(), level, words, }, token) onSaved() } catch (e) { setError(e instanceof Error ? e.message : 'Fehler beim Speichern') } finally { setSaving(false) } } return (
{/* Level slider */}
setLevel(Number(e.target.value))} style={{ width: '100%' }} />
{/* Question (optional) */}