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 (
{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
) )}