import React from 'react'; import { View, Text, TextInput, TouchableOpacity, Alert } from 'react-native'; import { useAppTheme } from '@theme'; import Svg, { Path } from 'react-native-svg'; import { pick, types, errorCodes } from '@react-native-documents/picker'; import { getStyles } from './KycDocumentCard.styles'; export interface KycDocument { id: string; name: string; idNumber: string; fileName: string | null; fileUri?: string | null; fileType?: string | null; status?: string; } interface KycDocumentCardProps { document: KycDocument; index: number; onUpdate?: (updatedFields: Partial) => void; onRemove?: () => void; readOnly?: boolean; } const UploadIcon = ({ size = 18, color = '#666' }) => ( ); export const KycDocumentCard: React.FC = ({ document, index, onUpdate, onRemove, readOnly = false, }) => { const { colors } = useAppTheme(); const styles = getStyles(colors); const handleSelectFile = async () => { if (readOnly) return; try { const [result] = await pick({ type: [types.pdf, types.images], allowMultiSelection: false, }); onUpdate?.({ fileName: result.name ?? `document_${Date.now()}`, fileUri: result.uri, fileType: result.type ?? 'application/octet-stream', }); } catch (err: any) { if (err?.code === errorCodes.OPERATION_CANCELED) { // User dismissed the picker — no action needed return; } Alert.alert('File Picker Error', err?.message ?? 'Failed to open document picker.'); } }; const renderStatusBadge = (status?: string) => { if (!status) return null; const normalized = status.toLowerCase(); let bgColor = '#FFF9E6'; let textColor = '#B27B00'; let label = status; if (normalized === 'verified' || normalized === 'approved') { bgColor = '#E6F4EA'; textColor = '#137333'; label = 'Verified'; } else if (normalized === 'rejected' || normalized === 'failed') { bgColor = '#FCE8E6'; textColor = '#C5221F'; label = 'Rejected'; } else if (normalized === 'pending' || normalized === 'submitted' || normalized === 'under_review') { bgColor = '#FFF9E6'; textColor = '#B27B00'; label = 'Pending'; } return ( {label} ); }; return ( Document {index + 1} {readOnly && renderStatusBadge(document.status)} {!readOnly && onRemove && ( Remove )} {/* Document Name / Type */} Document Name / Type onUpdate?.({ name: text })} autoCapitalize="sentences" editable={!readOnly} /> {/* Document Identification Number */} Document Identification Number onUpdate?.({ idNumber: text })} autoCapitalize="characters" editable={!readOnly} /> {/* Document Attachment */} Document Attachment File (JPG, PNG, PDF) {document.fileName ? document.fileName : 'SELECT DOCUMENT FILE...'} {!readOnly && } {!readOnly && ( Supported: pdf, png, jpg, or jpeg under 200kb only. )} ); }; export default KycDocumentCard;