import React, { useState } from 'react'; import { View, Text, FlatList, TouchableOpacity, StyleSheet, TextInput, Alert } from 'react-native'; import { pick } from '@react-native-documents/picker'; import Animated, { FadeInDown, FadeOutUp, Layout } from 'react-native-reanimated'; // import BouncyCheckbox from 'react-native-bouncy-checkbox'; import { InsideHeader, Skelton } from '../../Component/Index'; import colors from '../../Constant/Color'; import EmdComplete from './Component/EmdComplete'; import NavigationString from '../../Constant/NavigationString'; import { useNavigation } from '@react-navigation/native'; const DUMMY_AUCTION_ITEMS = [ { id: 1, productName: 'Iron Scrap Lot A', emdAmount: 50000, itemDocumentName: null }, { id: 2, productName: 'Steel Rods Lot B', emdAmount: 75000, itemDocumentName: 'old_emd.pdf' }, { id: 3, productName: 'Copper Wire Lot C', emdAmount: 60000, itemDocumentName: null }, ]; type SelectedItem = { auctionItemId: number; productImageName: string; file: { name: string; uri: string; type: string; } | null; }; const Emd = () => { const Navigation: any = useNavigation() const [selectedItems, setSelectedItems] = useState([]); const [acceptedPolicy, setAcceptedPolicy] = useState(false); const [isComplete, setIsComplete] = useState(false); /* ---------------- Helpers ---------------- */ const isSelected = (id: number) => selectedItems.some(i => i.auctionItemId === id); const toggleSelect = (item: any, checked: boolean) => { if (!checked) { setSelectedItems(prev => prev.filter(i => i.auctionItemId !== item.id), ); } else { setSelectedItems(prev => [ ...prev, { auctionItemId: item.id, productImageName: '', file: null }, ]); } }; const updateSelectedItem = (id: number, data: Partial) => { setSelectedItems(prev => prev.map(i => (i.auctionItemId === id ? { ...i, ...data } : i)), ); }; const pickFile = async (id: number) => { try { const res = await pick({ type: ['application/pdf'] }); const file = res[0]; updateSelectedItem(id, { file: { name: file.name ?? 'document.pdf', uri: file.uri, type: 'application/pdf', }, }); } catch { console.log('Pick cancelled'); } }; const handleSubmit = () => { if (!acceptedPolicy) { Alert.alert('Policy Required', 'Please accept terms'); return; } if (selectedItems.length === 0) { Alert.alert('Select Item', 'Please select at least one item'); return; } for (const item of selectedItems) { if (!item.productImageName || !item.file) { Alert.alert('Incomplete', 'Upload documents for all selected items'); return; } } console.log('✅ SUBMITTED:', selectedItems); setIsComplete(true); }; /* ---------------- Render Item ---------------- */ const renderItem = ({ item }: any) => { const selected = isSelected(item.id); const selectedData = selectedItems.find( i => i.auctionItemId === item.id, ); return ( {item.productName} EMD ₹ {item.emdAmount} {/* toggleSelect(item, checked)} /> */} Existing Doc:{' '} {item.itemDocumentName ?? 'Not Uploaded'} {selected && ( updateSelectedItem(item.id, { productImageName: text }) } style={styles.input} /> pickFile(item.id)} > {selectedData?.file ? 'Change PDF' : 'Upload PDF'} {selectedData?.file && ( {selectedData.file.name} )} )} ); }; return ( {false ? ( ) : true ? ( { Navigation.navigate(NavigationString.StartBidding) }} /> ) : <> item.id.toString()} renderItem={renderItem} contentContainerStyle={{ paddingBottom: 170 }} /> {/* setAcceptedPolicy(p => !p)} text="I agree to Terms & Privacy Policy" textStyle={styles.policyText} /> */} Submit EMD } ); }; export default Emd; const styles = StyleSheet.create({ container: { flex: 1, paddingHorizontal: 10 }, card: { backgroundColor: '#FFFFFF', marginHorizontal: 5, marginTop: 16, padding: 18, borderRadius: 8, elevation: 5, overflow: 'hidden' }, cardSelected: { backgroundColor: colors.primaryHighlight, borderWidth: 1.5, borderColor: colors.primary, }, cardHeader: { width: '100%', flexDirection: 'row', justifyContent: 'space-between', }, title: { fontSize: 17, fontWeight: '800', color: '#0F172A', }, subText: { fontSize: 13, color: '#64748B', marginTop: 6, }, meta: { marginTop: 10, fontSize: 13, color: '#475569', }, bold: { fontWeight: '700', color: '#020617', }, form: { marginTop: 16, paddingTop: 16, borderTopWidth: 1, borderColor: '#E2E8F0', }, input: { borderWidth: 1, borderColor: '#CBD5E1', borderRadius: 14, padding: 12, backgroundColor: '#FFFFFF', fontSize: 14, }, uploadBtn: { marginTop: 12, backgroundColor: colors.primary, paddingVertical: 13, borderRadius: 14, alignItems: 'center', shadowColor: colors.primaryHighlight, shadowOffset: { width: 0, height: 6 }, shadowOpacity: 0.3, shadowRadius: 12, elevation: 4, }, uploadText: { color: '#FFFFFF', fontWeight: '800', fontSize: 14, }, fileName: { marginTop: 8, fontSize: 12, color: '#475569', }, bottom: { position: 'absolute', bottom: 0, left: 0, right: 0, padding: 16, backgroundColor: '#FFFFFF', borderTopWidth: 1, borderColor: '#E2E8F0', shadowColor: '#000', shadowOffset: { width: 0, height: -6 }, shadowOpacity: 0.08, shadowRadius: 14, elevation: 12, }, policyText: { fontSize: 13, color: '#334155', }, submitBtn: { marginTop: 14, backgroundColor: colors.primary, paddingVertical: 15, borderRadius: 16, alignItems: 'center', shadowColor: colors.primaryHighlight, shadowOffset: { width: 0, height: 8 }, shadowOpacity: 0.32, shadowRadius: 16, elevation: 6, }, disabled: { backgroundColor: colors.lightText }, submitText: { color: '#FFFFFF', fontWeight: '800', fontSize: 15, }, });