import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import '../../features/auth/presentation/controllers/dev_auth_bypass.dart'; class AdaptiveHomeScaffold extends ConsumerWidget { final Widget child; const AdaptiveHomeScaffold({ super.key, required this.child, }); int _calculateSelectedIndex(BuildContext context) { final location = GoRouterState.of(context).uri.toString(); if (location.startsWith('/medication')) return 0; if (location.startsWith('/nutrition')) return 1; if (location.startsWith('/meal-planner')) return 2; if (location.startsWith('/pantry')) return 3; return 0; } void _onItemTapped(int index, BuildContext context) { switch (index) { case 0: context.go('/medication'); break; case 1: context.go('/nutrition'); break; case 2: context.go('/meal-planner'); break; case 3: context.go('/pantry'); break; } } @override Widget build(BuildContext context, WidgetRef ref) { final width = MediaQuery.of(context).size.width; final isDesktop = width >= 1024; final selectedIndex = _calculateSelectedIndex(context); // Visual marker while the debug auth bypass is active, so a review // session can never be mistaken for a signed-in one. final showDevBanner = kDebugMode && ref.watch(devAuthBypassProvider); if (isDesktop) { return Scaffold( body: Column( children: [ if (showDevBanner) const _DevAccessBanner(), Expanded( child: Row( children: [ NavigationRail( selectedIndex: selectedIndex, onDestinationSelected: (idx) => _onItemTapped(idx, context), labelType: NavigationRailLabelType.all, destinations: const [ NavigationRailDestination( icon: Icon(Icons.medication_outlined), selectedIcon: Icon(Icons.medication), label: Text('Medication'), ), NavigationRailDestination( icon: Icon(Icons.restaurant_outlined), selectedIcon: Icon(Icons.restaurant), label: Text('Nutrition'), ), NavigationRailDestination( icon: Icon(Icons.calendar_month_outlined), selectedIcon: Icon(Icons.calendar_month), label: Text('Meal Plan'), ), NavigationRailDestination( icon: Icon(Icons.kitchen_outlined), selectedIcon: Icon(Icons.kitchen), label: Text('Pantry'), ), ], ), const VerticalDivider(thickness: 1, width: 1), Expanded(child: child), ], ), ), ], ), ); } return Scaffold( body: Column( children: [ if (showDevBanner) const _DevAccessBanner(), Expanded(child: child), ], ), bottomNavigationBar: NavigationBar( selectedIndex: selectedIndex, onDestinationSelected: (idx) => _onItemTapped(idx, context), destinations: const [ NavigationDestination( icon: Icon(Icons.medication_outlined), selectedIcon: Icon(Icons.medication), label: 'Meds', ), NavigationDestination( icon: Icon(Icons.restaurant_outlined), selectedIcon: Icon(Icons.restaurant), label: 'Food', ), NavigationDestination( icon: Icon(Icons.calendar_month_outlined), selectedIcon: Icon(Icons.calendar_month), label: 'Plan', ), NavigationDestination( icon: Icon(Icons.kitchen_outlined), selectedIcon: Icon(Icons.kitchen), label: 'Pantry', ), ], ), ); } } /// Slim status strip shown while the development auth bypass is active. class _DevAccessBanner extends StatelessWidget { const _DevAccessBanner(); @override Widget build(BuildContext context) { return Material( color: Colors.orange, child: SafeArea( bottom: false, child: Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6), child: Row( children: [ const Icon(Icons.bug_report_outlined, size: 16, color: Colors.white), const SizedBox(width: 8), Expanded( child: Text( 'Development mode - not signed in', style: Theme.of(context).textTheme.labelMedium?.copyWith( color: Colors.white, ), ), ), ], ), ), ), ); } }