import React, { useState, useEffect } from 'react'; import { View, Text, TouchableOpacity, Switch, StyleSheet, Alert, Share, ScrollView, } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { MaterialIcons } from '@expo/vector-icons'; import { kv } from '../../src/lib/kv'; import { useHouseholdStore } from '../../src/hooks/useHousehold'; import { regenerateInviteToken, buildInviteLink } from '../../src/services/household'; import { updateFcmToken, requestNotificationPermission } from '../../src/services/notifications'; import { COLORS } from '../../src/constants'; import Toast from 'react-native-toast-message'; const NOTIF_KEY = 'houseorg_notifications_enabled'; export default function SettingsScreen() { const household = useHouseholdStore((s) => s.household); const setHousehold = useHouseholdStore((s) => s.setHousehold); const [notificationsEnabled, setNotificationsEnabled] = useState(null); useEffect(() => { kv.getItem(NOTIF_KEY).then((val) => { setNotificationsEnabled(val !== 'false'); }); }, []); const handleShareInvite = async () => { if (!household) return; const link = buildInviteLink(household.id, household.inviteToken); const text = `Tritt unserem Haushalt bei: ${link}`; if (typeof navigator !== 'undefined' && (navigator as any).share) { await (navigator as any).share({ text, title: 'HouseOrg Einladung' }); } else if (typeof navigator !== 'undefined' && (navigator as any).clipboard) { await (navigator as any).clipboard.writeText(text); Toast.show({ type: 'success', text1: 'Link kopiert' }); } else { await Share.share({ message: text, title: 'HouseOrg Einladung' }); } }; const handleRegenerateLink = async () => { if (!household) return; Alert.alert( 'Link erneuern', 'Der alte Link wird ungültig. Alle Mitglieder können sich damit nicht mehr neu anmelden.', [ { text: 'Abbrechen', style: 'cancel' }, { text: 'Erneuern', style: 'destructive', onPress: async () => { try { const newToken = await regenerateInviteToken(household.id); setHousehold({ ...household, inviteToken: newToken }); Toast.show({ type: 'success', text1: 'Neuer Einladungslink erstellt' }); } catch { Toast.show({ type: 'error', text1: 'Fehler beim Erneuern' }); } }, }, ] ); }; const handleNotificationToggle = async (enabled: boolean) => { if (!household) return; if (enabled) { const granted = await requestNotificationPermission(); if (!granted) { Toast.show({ type: 'error', text1: 'Benachrichtigungen nicht erlaubt' }); return; } } setNotificationsEnabled(enabled); await kv.setItem(NOTIF_KEY, String(enabled)); await updateFcmToken(household.id, enabled); }; return ( Haushalt Name {household?.name} Einladungslink teilen Mitglieder einladen Einladungslink erneuern Alter Link wird ungültig Benachrichtigungen Push-Benachrichtigungen Einkaufsliste & MHD-Warnungen App Version 1.0.0 ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: COLORS.surface }, section: { marginTop: 28, paddingHorizontal: 16 }, sectionTitle: { fontSize: 12, fontWeight: '600', color: COLORS.textSecondary, textTransform: 'uppercase', letterSpacing: 0.6, marginBottom: 10, }, card: { backgroundColor: COLORS.white, borderRadius: 16, overflow: 'hidden', shadowColor: '#000', shadowOpacity: 0.05, shadowRadius: 8, elevation: 1, }, row: { flexDirection: 'row', alignItems: 'center', padding: 14, gap: 12, }, iconWrap: { width: 34, height: 34, borderRadius: 10, justifyContent: 'center', alignItems: 'center', }, rowContent: { flex: 1 }, rowLabel: { fontSize: 15, fontWeight: '500', color: COLORS.text }, rowValue: { fontSize: 13, color: COLORS.textSecondary, marginTop: 2 }, rowHint: { fontSize: 12, color: COLORS.textSecondary, marginTop: 1 }, divider: { height: StyleSheet.hairlineWidth, backgroundColor: COLORS.border, marginLeft: 60 }, });