import { type CSSProperties, useState } from 'react' import type { FieldEntry, FieldReview } from './types' import { useStore } from './store' interface Props { entry: FieldEntry sessionId: string isActive: boolean review?: FieldReview onClick: () => void } export function FieldRow({ entry, sessionId, isActive, review, onClick }: Props) { const [editing, setEditing] = useState(false) const [editValue, setEditValue] = useState(entry.value ?? '') const verifyField = useStore((s) => s.verifyField) const overrideField = useStore((s) => s.overrideField) const rejectField = useStore((s) => s.rejectField) const displayValue = review?.action === 'override' && review.overridden_value != null ? review.overridden_value : entry.value const isVerified = review?.action === 'verify' const isRejected = review?.action === 'reject' const isOverridden = review?.action === 'override' const borderStyle: CSSProperties = isVerified ? { borderColor: '#16a34a', backgroundColor: '#f0fdf4' } : isRejected ? { borderColor: '#fca5a5', backgroundColor: '#fef2f2' } : isOverridden ? { borderColor: '#2563EB', backgroundColor: '#eff6ff' } : isActive ? { borderColor: '#008080', backgroundColor: '#f0fdfc' } : { borderColor: 'transparent', backgroundColor: '#ffffff' } const handleSaveOverride = async () => { await overrideField(sessionId, entry.fieldPath, editValue) setEditing(false) } return (
{/* Label + value */}
{entry.label} {isVerified && ( Verified )} {isOverridden && ( Overridden )} {isRejected && ( Flagged )}
{/* Value */} {editing ? (
e.stopPropagation()} > setEditValue(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') handleSaveOverride() if (e.key === 'Escape') setEditing(false) }} />
) : (

{displayValue ?? ( Not extracted )}

)} {/* Provenance source hint — or explicit "no location" notice */} {!editing && ( entry.provenance ? (

{entry.provenance.source_filename} · p.{entry.provenance.location.page} ·{' '} "{entry.provenance.matched_text.slice(0, 60)}{entry.provenance.matched_text.length > 60 ? '…' : ''}"

) : (

No location data

) )}
{/* Right side: confidence badge + action buttons */}
e.stopPropagation()} > {entry.provenance && ( )} {/* Verify */} {/* Edit */} {/* Flag */}
) } function ConfidenceBadge({ score }: { score: number }) { const pct = Math.round(score * 100) const [bg, text] = pct >= 90 ? ['bg-green-100 text-green-700', ''] : pct >= 70 ? ['bg-yellow-100 text-yellow-700', ''] : ['bg-red-100 text-red-600', ''] return ( {pct}% ) } function CheckIcon() { return ( ) }