import React from 'react'; import clsx from 'clsx'; import { MdOutlineInfo, MdLock, MdLockOpen, MdError } from 'react-icons/md'; import { useTranslation } from '@/hooks/useTranslation'; const inputBaseStyles = 'w-full rounded-md px-3 py-2 focus:outline-none focus:ring-1 focus:ring-blue-500'; const inputBackgroundStyles = 'bg-base-200/50'; const labelStyles = 'text-base-content block text-sm font-medium'; interface SourceIndicatorProps { source?: string; } const SourceIndicator: React.FC = ({ source }) => { if (!source) return null; const [sourceName, confidence] = source.split('-'); const confidenceNum = parseInt(confidence!); let color = 'text-green-500'; if (confidenceNum < 90) color = 'text-yellow-500'; if (confidenceNum < 70) color = 'text-red-500'; return (
{sourceName} ({confidence}%)
); }; interface LockButtonProps { isLocked: boolean; onToggle: () => void; disabled?: boolean; } const LockButton: React.FC = ({ isLocked, onToggle, disabled = false }) => { return ( ); }; interface FormFieldProps { type?: 'input' | 'textarea'; field: string; label: string; isNumber?: boolean; required?: boolean; disabled?: boolean; lockable?: boolean; fieldSources: Record; lockedFields: Record; fieldErrors: Record; onToggleFieldLock: (field: string) => void; value: string; onFieldChange: (field: string, value: string) => void; placeholder?: string; rows?: number; className?: string; } const FormField: React.FC = ({ type = 'input', field, label, fieldSources, lockedFields, fieldErrors, isNumber = false, required = false, lockable = true, disabled = false, onToggleFieldLock, value, onFieldChange, placeholder, rows, className, }) => { const _ = useTranslation(); const isLocked = lockedFields[field]!; const source = fieldSources[field]!; const error = fieldErrors[field]!; return (
{label} {required && '*'} {isLocked && ( {_('Locked')} )}
{type === 'input' ? ( onFieldChange(field, e.target.value)} placeholder={isLocked ? '' : placeholder} disabled={disabled || isLocked} className={clsx( inputBaseStyles, inputBackgroundStyles, lockable && 'pe-10', isLocked ? 'cursor-not-allowed' : 'bg-gray-100 text-gray-500', error && 'border-red-500 focus:ring-red-500', className, )} /> ) : (