import { View, Text, Modal, ScrollView, TouchableOpacity, KeyboardAvoidingView, Platform } from 'react-native'; import { useState, useEffect } from 'react'; import { X } from 'lucide-react-native'; import { Input } from '@/components/ui/Input'; import { Button } from '@/components/ui/Button'; import { getDatabase } from '@/lib/database'; import { Contact } from '@/store/useContactStore'; const STATUS_OPTIONS = ['Active', 'Return Visit', 'Bible Study', 'Not Interested', 'Do Not Call']; const CATEGORY_OPTIONS = ['Adult', 'Teenager', 'Kid']; interface Props { contact: Contact; visible: boolean; onClose: () => void; onSaved: () => void; } export function EditContactSheet({ contact, visible, onClose, onSaved }: Props) { const [fullName, setFullName] = useState(contact.fullName); const [address, setAddress] = useState(contact.address ?? ''); const [status, setStatus] = useState(contact.status); const [category, setCategory] = useState(contact.category); const [notes, setNotes] = useState(contact.notes ?? ''); const [loading, setLoading] = useState(false); useEffect(() => { setFullName(contact.fullName); setAddress(contact.address ?? ''); setStatus(contact.status); setCategory(contact.category); setNotes(contact.notes ?? ''); }, [contact]); async function handleSave() { if (!fullName.trim()) return; setLoading(true); try { const db = await getDatabase(); const now = Math.floor(Date.now() / 1000); await db.runAsync( 'UPDATE contacts SET full_name=?, address=?, status=?, category=?, notes=?, updated_at=? WHERE id=?', [fullName.trim(), address.trim() || null, status, category, notes.trim() || null, now, contact.id] ); onSaved(); } finally { setLoading(false); } } return ( Edit Contact Status {STATUS_OPTIONS.map((s) => ( setStatus(s as any)} className={`px-3 py-1.5 rounded-full border ${status === s ? 'bg-primary border-primary' : 'bg-white border-gray-200'}`}> {s} ))} Category {CATEGORY_OPTIONS.map((c) => ( setCategory(c as any)} className={`px-3 py-1.5 rounded-full border ${category === c ? 'bg-primary border-primary' : 'bg-white border-gray-200'}`}> {c} ))}