import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:lucide_icons/lucide_icons.dart'; import '../providers/theme_provider.dart'; // Access userProfileProvider import 'home_screen.dart'; import 'soul_screen.dart'; import 'shop_settings_screen.dart'; import 'placeholders/placeholders.dart'; class MainScreen extends ConsumerStatefulWidget { const MainScreen({super.key}); @override ConsumerState createState() => _MainScreenState(); } class _MainScreenState extends ConsumerState { int _currentIndex = 0; @override Widget build(BuildContext context) { // Listen for mode changes to reset navigation to Home ref.listen(userProfileProvider.select((value) => value.isBusinessMode), (previous, next) { if (previous != next) { setState(() { _currentIndex = 0; }); } }); final userProfile = ref.watch(userProfileProvider); final isBusiness = userProfile.isBusinessMode; // Define Screens for each mode final List screens = isBusiness ? [ const HomeScreen(), // Inventory Management (FAB opens Menu Creation) const InstaSupportScreen(), // Social Media Support const AnalyticsScreen(), // Analytics const ShopSettingsScreen(), // Shop Settings ] : [ const HomeScreen(), // My Sake List const ScanARScreen(), const SommelierScreen(), const BreweryMapScreen(), const SoulScreen(), // MyPage/Settings ]; // Define Navigation Items final List destinations = isBusiness ? const [ NavigationDestination( icon: Padding(padding: EdgeInsets.only(bottom: 2), child: Text('🍢', style: TextStyle(fontSize: 22))), label: 'ホーム', ), NavigationDestination(icon: Icon(LucideIcons.instagram), label: '販促'), NavigationDestination(icon: Icon(LucideIcons.barChart), label: 'εˆ†ζž'), NavigationDestination(icon: Icon(LucideIcons.store), label: 'εΊ—θˆ—'), ] : const [ NavigationDestination( icon: Padding(padding: EdgeInsets.only(bottom: 2), child: Text('🍢', style: TextStyle(fontSize: 22))), label: 'ホーム', ), NavigationDestination(icon: Icon(LucideIcons.scanLine), label: 'スキャン'), NavigationDestination(icon: Icon(LucideIcons.sparkles), label: 'γ‚½γƒ γƒͺエ'), NavigationDestination(icon: Icon(LucideIcons.map), label: 'γƒžγƒƒγƒ—'), NavigationDestination(icon: Icon(LucideIcons.user), label: 'γƒžγ‚€γƒšγƒΌγ‚Έ'), ]; // Safety: Reset index if out of bounds (shouldn't happen if lengths match) if (_currentIndex >= screens.length) _currentIndex = 0; return Scaffold( body: SafeArea( child: IndexedStack( index: _currentIndex, children: screens, ), ), bottomNavigationBar: NavigationBar( selectedIndex: _currentIndex, onDestinationSelected: (index) { setState(() { _currentIndex = index; }); }, destinations: destinations, ), ); } }