import { View, Text, TextInput, TouchableOpacity, Alert } from 'react-native' import React, { useState } from 'react' import TabBar from '../themes/TabBar' import { ChevronLeftIcon } from 'react-native-heroicons/outline' import { useNavigation, useRoute } from '@react-navigation/native' import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen' export default function AddCardScreen() { const navigation = useNavigation(); const route = useRoute(); const { method } = route.params; const [cardNumber, setCardNumber] = useState(''); const [expiryDate, setExpiryDate] = useState(''); const [cvv, setCvv] = useState(''); const [cardholderName, setCardholderName] = useState(''); const [isLoading, setIsLoading] = useState(false); const formatCardNumber = (text) => { // Remove all non-digit characters const cleaned = text.replace(/\D/g, ''); // Add space after every 4 digits const formatted = cleaned.replace(/(\d{4})/g, '$1 ').trim(); setCardNumber(formatted); }; const formatExpiryDate = (text) => { // Remove all non-digit characters const cleaned = text.replace(/\D/g, ''); // Add slash after 2 digits if (cleaned.length >= 2) { const formatted = cleaned.slice(0, 2) + '/' + cleaned.slice(2, 4); setExpiryDate(formatted); } else { setExpiryDate(cleaned); } }; const handleAddCard = async () => { try { setIsLoading(true); // Basic validation if (!cardNumber || !expiryDate || !cvv || !cardholderName) { Alert.alert('Error', 'Please fill in all card details'); return; } if (cardNumber.replace(/\s/g, '').length !== 16) { Alert.alert('Error', 'Please enter a valid 16-digit card number'); return; } if (cvv.length < 3) { Alert.alert('Error', 'Please enter a valid CVV'); return; } // Here you would typically make an API call to save the card // For now, we'll just show a success message Alert.alert( 'Success', 'Card added successfully!', [ { text: 'OK', onPress: () => navigation.goBack() } ] ); } catch (error) { console.error('Error adding card:', error); Alert.alert('Error', 'Failed to add card. Please try again.'); } finally { setIsLoading(false); } }; return ( } titleStyle={{ color: "black", fontWeight: "bold", fontSize: 20 }} prefixStyle={{ backgroundColor: "transparent" }} suffixStyle={{ backgroundColor: "white", borderWidth: 1, borderColor: "black" }} containerStyle="" suffixAction={() => navigation.goBack()} /> Card Details Enter your card information securely Cardholder Name Card Number Expiry Date CVV {isLoading ? 'Adding Card...' : 'Add Card'} Your card details are encrypted and secure. We never store your full card number. ) }