import Ionicons from '@expo/vector-icons/Ionicons'; import { StatusBar } from 'expo-status-bar'; import { type Href, useRouter } from 'expo-router'; import React, { useState } from 'react'; import { ActivityIndicator, Alert, Pressable, StyleSheet, Text, View, } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { useColorScheme } from '@/hooks/use-color-scheme'; import { authClient } from '@/lib/auth/client'; type Palette = { canvas: string; card: string; textPrimary: string; textSecondary: string; icon: string; stroke: string; buttonBackground: string; buttonText: string; }; type SettingDestination = { key: string; label: string; route?: Href; }; const palettes: Record<'dark' | 'light', Palette> = { dark: { canvas: '#050505', card: '#141417', textPrimary: '#F5F5F7', textSecondary: '#8E8E93', icon: '#F5F5F7', stroke: '#232327', buttonBackground: '#FFFFFF', buttonText: '#050505', }, light: { canvas: '#F7F7F9', card: '#FFFFFF', textPrimary: '#131318', textSecondary: '#5C5C67', icon: '#131318', stroke: '#E4E4EA', buttonBackground: '#131318', buttonText: '#FFFFFF', }, }; const destinations: SettingDestination[] = [ { key: 'change-password', label: 'Change Password', route: '/settings/account' }, { key: 'terms', label: 'Terms and Policies' }, { key: 'support', label: 'Feedback and Support' }, ]; export default function SettingsHomeScreen() { const router = useRouter(); const insets = useSafeAreaInsets(); const colorScheme = useColorScheme(); const palette = palettes[colorScheme === 'dark' ? 'dark' : 'light']; const [isLoggingOut, setIsLoggingOut] = useState(false); const topInset = Math.max(insets.top, 16); const bottomInset = Math.max(insets.bottom + 16, 40); const handleNavigate = (destination: SettingDestination) => { if (!destination.route) { return; } router.push(destination.route); }; const handleLogOut = async () => { if (isLoggingOut) { return; } setIsLoggingOut(true); try { await authClient.signOut(); router.replace('/(auth)/login'); } catch (error) { const message = error instanceof Error ? error.message : 'Please try again in a moment.'; Alert.alert('Unable to log out', message); } finally { setIsLoggingOut(false); } }; return ( router.back()} > set up {destinations.map((destination, index) => { const isLast = index === destinations.length - 1; return ( handleNavigate(destination)} style={({ pressed }) => [ styles.optionRow, !isLast && { borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: palette.stroke }, pressed && destination.route && { opacity: 0.6 }, ]} > {destination.label} ); })} [ styles.logoutButton, { backgroundColor: palette.buttonBackground }, pressed && { opacity: 0.9 }, ]} > {isLoggingOut ? ( ) : ( Log out )} ); } const styles = StyleSheet.create({ screen: { flex: 1, paddingHorizontal: 20, }, headerRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', marginBottom: 32, }, headerControl: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center', }, headerTitle: { fontSize: 18, fontWeight: '600', letterSpacing: 0.4, }, content: { flex: 1, }, card: { borderRadius: 18, paddingHorizontal: 20, }, optionRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', minHeight: 64, }, optionLabel: { fontSize: 16, fontWeight: '500', }, footer: { paddingTop: 32, }, logoutButton: { borderRadius: 26, height: 56, alignItems: 'center', justifyContent: 'center', }, logoutLabel: { fontSize: 16, fontWeight: '600', }, });