import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import '../router/app_router.dart'; import '../theme/app_colors.dart'; import 'wallet_chip.dart'; /// Coque principale — navigation + solde visible (style WashOnline amélioré). class MainShell extends ConsumerWidget { const MainShell({super.key, required this.child}); final Widget child; static int _indexFromLocation(String location) { if (location.startsWith(AppRoutes.bookings)) return 1; if (location.startsWith(AppRoutes.washes)) return 2; if (location.startsWith(AppRoutes.wallet)) return 3; if (location.startsWith(AppRoutes.profile)) return 4; return 0; } static String _titleFromLocation(String location) { if (location.startsWith(AppRoutes.bookings)) return 'Réservations'; if (location.startsWith(AppRoutes.washes)) return 'Mes lavages'; if (location.startsWith(AppRoutes.wallet)) return 'Portefeuille'; if (location.startsWith(AppRoutes.profile)) return 'Mon profil'; return 'Accueil'; } static bool _showScanFab(String location) { return location.startsWith(AppRoutes.bookings) || location.startsWith(AppRoutes.washes); } void _onTabTap(BuildContext context, int index) { switch (index) { case 0: context.go(AppRoutes.home); case 1: context.go(AppRoutes.bookings); case 2: context.go(AppRoutes.washes); case 3: context.go(AppRoutes.wallet); case 4: context.go(AppRoutes.profile); } } @override Widget build(BuildContext context, WidgetRef ref) { final location = GoRouterState.of(context).uri.toString(); final selectedIndex = _indexFromLocation(location); final showScanFab = _showScanFab(location); return Scaffold( backgroundColor: AppColors.background, appBar: AppBar( title: Text(_titleFromLocation(location)), actions: const [WalletChip()], ), body: child, floatingActionButton: showScanFab ? FloatingActionButton.extended( onPressed: () => context.push(AppRoutes.washScan), icon: const Icon(Icons.qr_code_scanner_rounded), label: const Text('Scanner'), ) : null, bottomNavigationBar: NavigationBar( selectedIndex: selectedIndex, onDestinationSelected: (index) => _onTabTap(context, index), destinations: const [ NavigationDestination( icon: Icon(Icons.home_outlined), selectedIcon: Icon(Icons.home_rounded), label: 'Accueil', ), NavigationDestination( icon: Icon(Icons.event_outlined), selectedIcon: Icon(Icons.event), label: 'Résa', ), NavigationDestination( icon: Icon(Icons.local_laundry_service_outlined), selectedIcon: Icon(Icons.local_laundry_service), label: 'Lavages', ), NavigationDestination( icon: Icon(Icons.account_balance_wallet_outlined), selectedIcon: Icon(Icons.account_balance_wallet), label: 'Wallet', ), NavigationDestination( icon: Icon(Icons.person_outline), selectedIcon: Icon(Icons.person), label: 'Profil', ), ], ), ); } }