'use client' import { useState, useEffect } from 'react' import type { SubSession } from '@/app/(admin)/ai/ocr-pipeline/types' const KLAUSUR_API = '/klausur-api' interface StepPageSplitProps { sessionId: string | null onNext: () => void onSubSessionsCreated: (subs: SubSession[]) => void } /** * Step 3: Page split detection. * Checks if the image is a double-page spread and offers to split it. * If no split needed, auto-advances. */ export function StepPageSplit({ sessionId, onNext, onSubSessionsCreated }: StepPageSplitProps) { const [checking, setChecking] = useState(false) const [splitResult, setSplitResult] = useState<{ is_double_page: boolean; pages?: number } | null>(null) const [splitting, setSplitting] = useState(false) const [error, setError] = useState('') useEffect(() => { if (!sessionId) return // Auto-check for page split checkPageSplit() // eslint-disable-next-line react-hooks/exhaustive-deps }, [sessionId]) const checkPageSplit = async () => { if (!sessionId) return setChecking(true) setError('') try { const res = await fetch(`${KLAUSUR_API}/api/v1/ocr-pipeline/sessions/${sessionId}`) if (!res.ok) throw new Error('Session nicht gefunden') const data = await res.json() // If sub-sessions already exist, this was already split if (data.sub_sessions?.length > 0) { onSubSessionsCreated(data.sub_sessions) onNext() return } // Check aspect ratio to guess if double-page // For now, just auto-advance (page-split detection happens in orientation step) setSplitResult({ is_double_page: false }) // Auto-advance if single page onNext() } catch (e) { setError(e instanceof Error ? e.message : String(e)) } finally { setChecking(false) } } const handleSplit = async () => { if (!sessionId) return setSplitting(true) setError('') try { const res = await fetch(`${KLAUSUR_API}/api/v1/ocr-pipeline/sessions/${sessionId}/page-split`, { method: 'POST', }) if (!res.ok) { const data = await res.json().catch(() => ({})) throw new Error(data.detail || 'Split fehlgeschlagen') } const data = await res.json() if (data.sub_sessions?.length > 0) { onSubSessionsCreated(data.sub_sessions) } onNext() } catch (e) { setError(e instanceof Error ? e.message : String(e)) } finally { setSplitting(false) } } if (checking) { return
Das Bild scheint eine Doppelseite zu sein. Soll es in zwei Einzelseiten aufgeteilt werden?