'use client' import { useEffect, useState } from 'react' import type { DewarpResult, DewarpGroundTruth } from '@/app/(admin)/ai/ocr-pipeline/types' interface DewarpControlsProps { dewarpResult: DewarpResult | null showGrid: boolean onToggleGrid: () => void onManualDewarp: (shearDegrees: number) => void onGroundTruth: (gt: DewarpGroundTruth) => void onNext: () => void isApplying: boolean } const METHOD_LABELS: Record = { vertical_edge: 'Vertikale Kanten', manual: 'Manuell', none: 'Keine Korrektur', } export function DewarpControls({ dewarpResult, showGrid, onToggleGrid, onManualDewarp, onGroundTruth, onNext, isApplying, }: DewarpControlsProps) { const [manualShear, setManualShear] = useState(0) const [gtFeedback, setGtFeedback] = useState<'correct' | 'incorrect' | null>(null) const [gtNotes, setGtNotes] = useState('') const [gtSaved, setGtSaved] = useState(false) // Initialize slider to auto-detected value when result arrives useEffect(() => { if (dewarpResult && dewarpResult.shear_degrees !== undefined) { setManualShear(dewarpResult.shear_degrees) } }, [dewarpResult?.shear_degrees]) const handleGroundTruth = (isCorrect: boolean) => { setGtFeedback(isCorrect ? 'correct' : 'incorrect') if (isCorrect) { onGroundTruth({ is_correct: true }) setGtSaved(true) } } const handleGroundTruthIncorrect = () => { onGroundTruth({ is_correct: false, corrected_shear: manualShear !== 0 ? manualShear : undefined, notes: gtNotes || undefined, }) setGtSaved(true) } return (
{/* Results */} {dewarpResult && (
Scherung:{' '} {dewarpResult.shear_degrees}°
Methode:{' '} {METHOD_LABELS[dewarpResult.method_used] || dewarpResult.method_used}
Konfidenz:{' '} {Math.round(dewarpResult.confidence * 100)}%
{/* Toggle */}
)} {/* Manual shear angle slider */} {dewarpResult && (
Scherwinkel (manuell)
-2.0° setManualShear(parseInt(e.target.value) / 100)} className="flex-1 h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer dark:bg-gray-700 accent-teal-500" /> +2.0° {manualShear.toFixed(2)}°

Scherung der vertikalen Achse in Grad. Positiv = Spalten nach rechts kippen, negativ = nach links.

)} {/* Ground Truth */} {dewarpResult && (
Spalten vertikal ausgerichtet?

Pruefen ob die Spaltenraender jetzt senkrecht zum Raster stehen.

{!gtSaved ? (
{gtFeedback === 'incorrect' && (