import React, { useState } from 'react'; import { View, Text, TouchableOpacity, StyleSheet, SafeAreaView, ScrollView, StatusBar, TextInput, Alert, ActivityIndicator, Modal, } from 'react-native'; import { useTranslation } from 'react-i18next'; import { useNavigation } from '@react-navigation/native'; import { usePezkuwi } from '../contexts/PezkuwiContext'; import { submitKycApplication, uploadToIPFS, FOUNDER_ADDRESS, } from '@pezkuwi/lib/citizenship-workflow'; import type { Region, MaritalStatus } from '@pezkuwi/lib/citizenship-workflow'; import { KurdistanColors } from '../theme/colors'; // Temporary custom picker component (until we fix @react-native-picker/picker installation) const CustomPicker: React.FC<{ selectedValue: Region; onValueChange: (value: Region) => void; options: Array<{ label: string; value: Region }>; }> = ({ selectedValue, onValueChange, options }) => { const [isVisible, setIsVisible] = useState(false); const selectedOption = options.find(opt => opt.value === selectedValue); return ( <> setIsVisible(true)} > {selectedOption?.label || 'Select Region'} setIsVisible(false)} > setIsVisible(false)} > Select Your Region setIsVisible(false)}> {options.map((option) => ( { onValueChange(option.value); setIsVisible(false); }} > {option.label} {selectedValue === option.value && ( )} ))} ); }; const BeCitizenApplyScreen: React.FC = () => { const { t } = useTranslation(); const navigation = useNavigation(); const { api, selectedAccount } = usePezkuwi(); const [isSubmitting, setIsSubmitting] = useState(false); // Form State const [fullName, setFullName] = useState(''); const [fatherName, setFatherName] = useState(''); const [grandfatherName, setGrandfatherName] = useState(''); const [motherName, setMotherName] = useState(''); const [tribe, setTribe] = useState(''); const [maritalStatus, setMaritalStatus] = useState('nezewici'); const [childrenCount, setChildrenCount] = useState(0); const [children, setChildren] = useState>([]); const [region, setRegion] = useState('basur'); const [email, setEmail] = useState(''); const [profession, setProfession] = useState(''); const [referralCode, setReferralCode] = useState(''); const regionOptions = [ { label: 'Bakur (North - Turkey/Türkiye)', value: 'bakur' as Region }, { label: 'Başûr (South - Iraq)', value: 'basur' as Region }, { label: 'Rojava (West - Syria)', value: 'rojava' as Region }, { label: 'Rojhilat (East - Iran)', value: 'rojhelat' as Region }, { label: 'Kurdistan a Sor (Red Kurdistan)', value: 'kurdistan_a_sor' as Region }, { label: 'Diaspora (Living Abroad)', value: 'diaspora' as Region }, ]; const handleChildCountChange = (count: number) => { setChildrenCount(count); // Initialize children array const newChildren = Array.from({ length: count }, (_, i) => children[i] || { name: '', birthYear: new Date().getFullYear() } ); setChildren(newChildren); }; const updateChild = (index: number, field: 'name' | 'birthYear', value: string | number) => { const updated = [...children]; if (field === 'name') { updated[index].name = value as string; } else { updated[index].birthYear = value as number; } setChildren(updated); }; const handleSubmit = async () => { if (!fullName || !fatherName || !grandfatherName || !motherName || !tribe || !region || !email || !profession) { Alert.alert('Error', 'Please fill in all required fields'); return; } if (!api || !selectedAccount) { Alert.alert('Error', 'Please connect your wallet first'); return; } setIsSubmitting(true); try { // Prepare citizenship data const citizenshipData = { fullName, fatherName, grandfatherName, motherName, tribe, maritalStatus, childrenCount: maritalStatus === 'zewici' ? childrenCount : 0, children: maritalStatus === 'zewici' ? children.filter(c => c.name) : [], region, email, profession, referralCode: referralCode || FOUNDER_ADDRESS, // Auto-assign to founder if empty walletAddress: selectedAccount.address, timestamp: Date.now(), }; // Step 1: Upload encrypted data to IPFS const ipfsCid = await uploadToIPFS(citizenshipData); if (!ipfsCid) { throw new Error('Failed to upload data to IPFS'); } // Step 2: Submit KYC application to blockchain const result = await submitKycApplication( api, selectedAccount, citizenshipData.fullName, citizenshipData.email, String(ipfsCid), 'Citizenship application via mobile app' ); if (result.success) { Alert.alert( 'Application Submitted!', 'Your citizenship application has been submitted for review. You will receive a confirmation once approved.', [ { text: 'OK', onPress: () => { navigation.goBack(); }, }, ] ); } else { Alert.alert('Application Failed', result.error || 'Failed to submit application'); } } catch (error: unknown) { if (__DEV__) console.error('Citizenship application error:', error); Alert.alert('Error', error instanceof Error ? error.message : 'An unexpected error occurred'); } finally { setIsSubmitting(false); } }; return ( Nasnameya Kesane Personal Identity - Citizenship Application {/* Personal Identity */} Personal Identity Navê Te (Your Full Name) * Navê Bavê Te (Father's Name) * Navê Bavkalê Te (Grandfather's Name) * Navê Dayika Te (Mother's Name) * {/* Tribal Affiliation */} Eşîra Te (Tribal Affiliation) Eşîra Te (Your Tribe) * {/* Family Status */} Rewşa Malbatê (Family Status) Zewicî / Nezewicî (Married / Unmarried) * setMaritalStatus('zewici')} > {maritalStatus === 'zewici' && } Zewicî (Married) setMaritalStatus('nezewici')} > {maritalStatus === 'nezewici' && } Nezewicî (Unmarried) {maritalStatus === 'zewici' && ( <> Hejmara Zarokan (Number of Children) handleChildCountChange(parseInt(text) || 0)} keyboardType="number-pad" placeholderTextColor="#999" /> {childrenCount > 0 && ( Navên Zarokan (Children's Names) {children.map((child, index) => ( updateChild(index, 'name', text)} placeholderTextColor="#999" /> updateChild(index, 'birthYear', parseInt(text) || new Date().getFullYear())} keyboardType="number-pad" placeholderTextColor="#999" /> ))} )} )} {/* Geographic Origin */} Herêma Te (Your Region) Ji Kuderê yî? (Where are you from?) * {/* Contact & Profession */} Têkilî û Pîşe (Contact & Profession) E-mail * Pîşeya Te (Your Profession) * {/* Referral */} Koda Referral (Referral Code - Optional) If you were invited by another citizen, enter their referral code If empty, you will be automatically linked to the Founder (Satoshi Qazi Muhammed) {isSubmitting ? ( ) : ( Submit Application )} ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#F5F5F5', }, formContainer: { flex: 1, padding: 20, }, formTitle: { fontSize: 24, fontWeight: 'bold', color: KurdistanColors.reş, marginBottom: 4, }, formSubtitle: { fontSize: 14, color: '#666', marginBottom: 24, }, section: { backgroundColor: KurdistanColors.spi, borderRadius: 12, padding: 16, marginBottom: 16, shadowColor: '#000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.05, shadowRadius: 4, elevation: 2, }, sectionTitle: { fontSize: 16, fontWeight: '700', color: KurdistanColors.kesk, marginBottom: 12, }, sectionDescription: { fontSize: 12, color: '#666', marginBottom: 12, }, referralSection: { backgroundColor: `${KurdistanColors.mor}10`, borderWidth: 1, borderColor: `${KurdistanColors.mor}30`, }, inputGroup: { marginBottom: 16, }, label: { fontSize: 14, fontWeight: '600', color: KurdistanColors.reş, marginBottom: 8, }, input: { backgroundColor: '#F8F9FA', borderRadius: 8, padding: 12, fontSize: 14, borderWidth: 1, borderColor: '#E0E0E0', color: KurdistanColors.reş, }, radioGroup: { gap: 12, }, radioButton: { flexDirection: 'row', alignItems: 'center', paddingVertical: 8, }, radioCircle: { width: 20, height: 20, borderRadius: 10, borderWidth: 2, borderColor: KurdistanColors.kesk, marginRight: 10, justifyContent: 'center', alignItems: 'center', }, radioSelected: { borderColor: KurdistanColors.kesk, }, radioDot: { width: 10, height: 10, borderRadius: 5, backgroundColor: KurdistanColors.kesk, }, radioLabel: { fontSize: 14, color: KurdistanColors.reş, }, childRow: { flexDirection: 'row', gap: 8, marginBottom: 8, }, childInput: { flex: 1, marginBottom: 0, }, pickerButton: { backgroundColor: '#F8F9FA', borderRadius: 8, borderWidth: 1, borderColor: '#E0E0E0', padding: 12, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', }, pickerButtonText: { fontSize: 14, color: KurdistanColors.reş, }, pickerArrow: { fontSize: 12, color: '#666', }, modalOverlay: { flex: 1, backgroundColor: 'rgba(0, 0, 0, 0.5)', justifyContent: 'flex-end', }, pickerModal: { backgroundColor: KurdistanColors.spi, borderTopLeftRadius: 20, borderTopRightRadius: 20, maxHeight: '70%', paddingBottom: 20, }, pickerHeader: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', padding: 16, borderBottomWidth: 1, borderBottomColor: '#E0E0E0', }, pickerTitle: { fontSize: 18, fontWeight: '700', color: KurdistanColors.reş, }, pickerClose: { fontSize: 24, color: '#666', fontWeight: '300', }, pickerOption: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', padding: 16, borderBottomWidth: 1, borderBottomColor: '#F0F0F0', }, pickerOptionSelected: { backgroundColor: `${KurdistanColors.kesk}10`, }, pickerOptionText: { fontSize: 15, color: KurdistanColors.reş, }, pickerOptionTextSelected: { fontWeight: '600', color: KurdistanColors.kesk, }, pickerCheckmark: { fontSize: 18, color: KurdistanColors.kesk, fontWeight: 'bold', }, helpText: { fontSize: 11, color: '#666', marginTop: 4, }, submitButton: { backgroundColor: KurdistanColors.kesk, borderRadius: 12, padding: 16, alignItems: 'center', marginTop: 20, shadowColor: KurdistanColors.kesk, shadowOffset: { width: 0, height: 4 }, shadowOpacity: 0.3, shadowRadius: 6, elevation: 6, }, submitButtonDisabled: { opacity: 0.6, }, submitButtonText: { fontSize: 18, fontWeight: 'bold', color: KurdistanColors.spi, }, spacer: { height: 40, }, }); export default BeCitizenApplyScreen;