import { View, Text, ScrollView, TouchableOpacity, Alert } from 'react-native'; import { useLocalSearchParams, router } from 'expo-router'; import { useState, useCallback } from 'react'; import { useFocusEffect } from 'expo-router'; import { ArrowLeft, Edit2, Trash2, MapPin, Phone } from 'lucide-react-native'; import { getDatabase } from '@/lib/database'; import { dbToContact } from '@/lib/contactHelpers'; import { Contact } from '@/store/useContactStore'; import { EditContactSheet } from '@/components/contacts/EditContactSheet'; const statusColors: Record = { 'Active': '#4CAF7D', 'Return Visit': '#2196F3', 'Bible Study': '#9C27B0', 'Not Interested': '#9CA3AF', 'Do Not Call': '#C0392B', }; export default function ContactDetailScreen() { const { id } = useLocalSearchParams<{ id: string }>(); const [contact, setContact] = useState(null); const [showEdit, setShowEdit] = useState(false); async function loadContact() { const db = await getDatabase(); const row = await db.getFirstAsync('SELECT * FROM contacts WHERE id = ?', [id]); if (row) setContact(dbToContact(row)); } useFocusEffect(useCallback(() => { loadContact(); }, [id])); async function handleDelete() { Alert.alert('Delete Contact', `Are you sure you want to delete ${contact?.fullName}?`, [ { text: 'Cancel', style: 'cancel' }, { text: 'Delete', style: 'destructive', onPress: async () => { const db = await getDatabase(); const now = Math.floor(Date.now() / 1000); await db.runAsync('UPDATE contacts SET deleted_at = ? WHERE id = ?', [now, id]); router.back(); } } ]); } if (!contact) return ; const statusColor = statusColors[contact.status] ?? '#9CA3AF'; return ( {/* Header */} router.back()} className="bg-white/20 rounded-full p-2"> setShowEdit(true)} className="bg-white/20 rounded-full p-2"> {contact.fullName.split(' ').map((n) => n[0]).join('').substring(0, 2).toUpperCase()} {contact.fullName} {contact.status} {/* Info Card */} Information {contact.address && } />} {contact.territoryCode && } {contact.notes && ( Notes {contact.notes} )} setShowEdit(false)} onSaved={() => { setShowEdit(false); loadContact(); }} /> ); } function Row({ label, value, icon }: { label: string; value: string; icon?: React.ReactNode }) { return ( {label} {icon} {value} ); }