import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:google_fonts/google_fonts.dart'; import '../../theme/app_theme.dart'; import '../../models/user_profile.dart'; import '../../providers/user_provider.dart'; import '../../services/mock_data_service.dart'; import 'husband_appearance_screen.dart'; import '../settings/sharing_settings_screen.dart'; class HusbandSettingsScreen extends ConsumerWidget { const HusbandSettingsScreen({super.key}); Future _resetApp(BuildContext context, WidgetRef ref) async { final confirmed = await showDialog( context: context, builder: (context) => AlertDialog( title: const Text('Reset App?'), content: const Text( 'This will clear all data and return you to onboarding. Are you sure?'), actions: [ TextButton( onPressed: () => Navigator.pop(context, false), child: const Text('Cancel')), TextButton( onPressed: () => Navigator.pop(context, true), child: const Text('Reset', style: TextStyle(color: Colors.red)), ), ], ), ); if (confirmed == true) { await ref.read(userProfileProvider.notifier).clearProfile(); await ref.read(cycleEntriesProvider.notifier).clearEntries(); if (context.mounted) { Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false); } } } Future _loadDemoData(BuildContext context, WidgetRef ref) async { final confirmed = await showDialog( context: context, builder: (context) => AlertDialog( title: const Text('Load Demo Data?'), content: const Text( 'This will populate the app with mock cycle entries and a wife profile.'), actions: [ TextButton( onPressed: () => Navigator.pop(context, false), child: const Text('Cancel')), TextButton( onPressed: () => Navigator.pop(context, true), child: const Text('Load Data', style: TextStyle(color: Colors.blue)), ), ], ), ); if (confirmed == true) { final mockService = MockDataService(); // Load mock entries final entries = mockService.generateMockCycleEntries(); for (var entry in entries) { await ref.read(cycleEntriesProvider.notifier).addEntry(entry); } // Update mock profile final mockWife = mockService.generateMockWifeProfile(); final currentProfile = ref.read(userProfileProvider); if (currentProfile != null) { final updatedProfile = currentProfile.copyWith( partnerName: mockWife.name, averageCycleLength: mockWife.averageCycleLength, averagePeriodLength: mockWife.averagePeriodLength, lastPeriodStartDate: mockWife.lastPeriodStartDate, favoriteFoods: mockWife.favoriteFoods, ); await ref .read(userProfileProvider.notifier) .updateProfile(updatedProfile); } if (context.mounted) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Demo data loaded')), ); } } } void _showTranslationPicker(BuildContext context, WidgetRef ref) { showModalBottomSheet( context: context, shape: const RoundedRectangleBorder( borderRadius: BorderRadius.vertical(top: Radius.circular(20)), ), builder: (context) => Container( padding: const EdgeInsets.all(20), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Choose Translation', style: GoogleFonts.outfit( fontSize: 20, fontWeight: FontWeight.w600, color: Theme.of(context).textTheme.titleLarge?.color, ), ), const SizedBox(height: 16), ...BibleTranslation.values.map((translation) => ListTile( title: Text( translation.label, style: GoogleFonts.outfit(fontWeight: FontWeight.w500), ), trailing: ref.watch(userProfileProvider)?.bibleTranslation == translation ? const Icon(Icons.check, color: AppColors.sageGreen) : null, onTap: () async { final profile = ref.read(userProfileProvider); if (profile != null) { await ref .read(userProfileProvider.notifier) .updateProfile( profile.copyWith(bibleTranslation: translation), ); } if (context.mounted) Navigator.pop(context); }, )), ], ), ), ); } @override Widget build(BuildContext context, WidgetRef ref) { // Theme aware colors final user = ref.watch(userProfileProvider); final cardColor = Theme.of(context).cardTheme.color; // Using theme card color final textColor = Theme.of(context).textTheme.bodyLarge?.color; return SafeArea( child: SingleChildScrollView( padding: const EdgeInsets.all(20), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Settings', style: GoogleFonts.outfit( fontSize: 28, fontWeight: FontWeight.w600, color: Theme.of(context).textTheme.displayMedium?.color ?? AppColors.navyBlue, ), ), const SizedBox(height: 24), Container( decoration: BoxDecoration( color: cardColor, borderRadius: BorderRadius.circular(12), ), child: Column( children: [ ListTile( leading: Icon(Icons.notifications_outlined, color: Theme.of(context).colorScheme.primary), title: Text('Notifications', style: GoogleFonts.outfit( fontWeight: FontWeight.w500, color: textColor)), trailing: Switch(value: true, onChanged: (val) {}), ), const Divider(height: 1), ListTile( leading: Icon(Icons.link, color: Theme.of(context).colorScheme.primary), title: Text( user?.partnerId != null ? 'Partner Settings' : 'Connect with Wife', style: GoogleFonts.outfit( fontWeight: FontWeight.w500, color: textColor)), subtitle: user?.partnerId != null && user?.partnerName != null ? Text('Linked with ${user!.partnerName}', style: GoogleFonts.outfit( fontSize: 12, color: Theme.of(context).colorScheme.primary)) : null, trailing: Icon(Icons.chevron_right, color: Theme.of(context).disabledColor), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => const SharingSettingsScreen(), ), ); }, ), const Divider(height: 1), ListTile( leading: Icon(Icons.menu_book_outlined, color: Theme.of(context).colorScheme.primary), title: Text('Bible Translation', style: GoogleFonts.outfit( fontWeight: FontWeight.w500, color: textColor)), trailing: Row( mainAxisSize: MainAxisSize.min, children: [ Text( ref.watch(userProfileProvider .select((u) => u?.bibleTranslation.label)) ?? 'ESV', style: GoogleFonts.outfit( fontSize: 14, color: Theme.of(context).textTheme.bodyMedium?.color ?? AppColors.warmGray, ), ), Icon(Icons.chevron_right, color: Theme.of(context).disabledColor), ], ), onTap: () => _showTranslationPicker(context, ref), ), const Divider(height: 1), ListTile( leading: Icon(Icons.palette_outlined, color: Theme.of(context).colorScheme.primary), title: Text('Appearance', style: GoogleFonts.outfit( fontWeight: FontWeight.w500, color: textColor)), trailing: Icon(Icons.chevron_right, color: Theme.of(context).disabledColor), onTap: () { Navigator.push( context, MaterialPageRoute( builder: (context) => const HusbandAppearanceScreen(), ), ); }, ), ], ), ), const SizedBox(height: 20), Container( decoration: BoxDecoration( color: cardColor, borderRadius: BorderRadius.circular(12), ), child: Column( children: [ ListTile( leading: const Icon(Icons.sync, color: Colors.blue), title: Text('Sync Data', style: GoogleFonts.outfit( fontWeight: FontWeight.w500, color: Colors.blue)), onTap: () async { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Syncing data...')), ); await ref.read(cycleEntriesProvider.notifier).syncData(); if (context.mounted) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('Sync complete'), backgroundColor: Colors.green, ), ); } }, ), const Divider(height: 1), ListTile( leading: const Icon(Icons.cloud_download_outlined, color: Colors.blue), title: Text('Load Demo Data', style: GoogleFonts.outfit( fontWeight: FontWeight.w500, color: Colors.blue)), onTap: () => _loadDemoData(context, ref), ), const Divider(height: 1), ListTile( leading: const Icon(Icons.logout, color: Colors.red), title: Text('Reset App', style: GoogleFonts.outfit( fontWeight: FontWeight.w500, color: Colors.red)), onTap: () => _resetApp(context, ref), ), ], ), ), ], ), ), ); } }