import { router } from 'expo-router'; import { StatusBar } from 'expo-status-bar'; import { useState } from 'react'; import { KeyboardAvoidingView, Platform, ScrollView, Text, TextInput, TouchableOpacity, View } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { getDB } from '../db'; export default function AddAssetScreen() { const insets = useSafeAreaInsets(); const [name, setName] = useState(''); const [type, setType] = useState('stock'); const [value, setValue] = useState(''); const [quantity, setQuantity] = useState(''); const handleSave = async () => { if (!name || !value) { alert('Please fill in name and value'); return; } try { const db = getDB(); await db.runAsync( 'INSERT INTO assets (name, type, value, quantity, purchase_date) VALUES (?, ?, ?, ?, ?)', [name, type, parseFloat(value), quantity ? parseFloat(quantity) : null, new Date().toISOString()] ); router.back(); } catch (error) { console.error(error); alert('Failed to save asset'); } }; return ( New Asset {/* Type Selector */} {['stock', 'crypto', 'real_estate', 'fund', 'other'].map((t) => ( setType(t)} className={`px-4 py-2 rounded-full border ${type === t ? 'bg-purple-600 border-purple-600' : 'bg-white border-gray-200 dark:bg-gray-800 dark:border-gray-700'}`} > {t.replace('_', ' ')} ))} {/* Value Input */} Current Value {/* Details Form */} Asset Name Quantity (Optional) Save Asset ); }