import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:lucide_icons/lucide_icons.dart'; import '../../../../core/theme/nature_colors.dart'; import '../../../inventory/presentation/product_list_screen.dart'; import '../../../inventory/presentation/quick_adjust_stock_screen.dart'; import '../../../inventory/presentation/uoms_list_screen.dart'; import '../../../sales/presentation/customers_list_screen.dart'; import '../../../sales/presentation/invoices_list_screen.dart'; import '../../providers/business_provider.dart'; import '../widgets/business_profile_form_sheet.dart'; class BusinessHubScreen extends ConsumerWidget { const BusinessHubScreen({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final businessState = ref.watch(businessProfileProvider); final profile = businessState.value; final title = (profile?.businessName != null && profile!.businessName.isNotEmpty) ? profile.businessName : 'Business Overview'; final subtitle = (profile?.address != null && profile!.address!.isNotEmpty) ? profile.address! : 'Manage your inventory and stock'; final featureState = ref.watch(businessFeatureProvider).value; final bool showInventory = featureState?.inventoryManagement ?? false; final bool showSales = featureState?.salesManagement ?? false; return SingleChildScrollView( padding: const EdgeInsets.all(24.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ InkWell( onTap: () { showModalBottomSheet( context: context, isScrollControlled: true, backgroundColor: Colors.transparent, builder: (context) => const BusinessProfileFormSheet(), ); }, borderRadius: BorderRadius.circular(16), child: Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: Theme.of(context).colorScheme.primary.withOpacity(0.1), borderRadius: BorderRadius.circular(16), border: Border.all(color: Theme.of(context).colorScheme.primary.withOpacity(0.2)), ), child: Row( children: [ Icon(LucideIcons.briefcase, color: Theme.of(context).colorScheme.primary, size: 32), const SizedBox(width: 16), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(title, style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold)), Text(subtitle, style: const TextStyle(color: Colors.grey)), ], ), ), ], ), ), ), const SizedBox(height: 24), GridView.count( crossAxisCount: 2, crossAxisSpacing: 16, mainAxisSpacing: 16, shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), childAspectRatio: 1.2, children: [ if (showInventory) ...[ _buildActionCard( context, 'Products Catalog', 'View all products', LucideIcons.packageSearch, Colors.blue, () => Navigator.push(context, MaterialPageRoute(builder: (_) => const ProductListScreen())), ), _buildActionCard( context, 'Adjust Stock', 'Quick Stock Edit', LucideIcons.arrowRightLeft, Colors.orange, () => Navigator.push(context, MaterialPageRoute(builder: (_) => const QuickAdjustStockScreen())), ), _buildActionCard( context, 'Units of Measure', 'Manage measurements', LucideIcons.ruler, Colors.purple, () => Navigator.push(context, MaterialPageRoute(builder: (_) => const UomsListScreen())), ), ], if (showSales) ...[ _buildActionCard( context, 'Sales & Invoices', 'Create invoices', LucideIcons.receipt, Colors.green, () => Navigator.push(context, MaterialPageRoute(builder: (_) => const InvoicesListScreen())), ), _buildActionCard( context, 'Customers', 'Manage clients', LucideIcons.users, NatureColors.getColor('RECEIVABLES'), () => Navigator.push(context, MaterialPageRoute(builder: (_) => const CustomersListScreen())), ), ], ], ), if (showInventory) ...[ const SizedBox(height: 32), Text('Low Stock Alerts', style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold)), const SizedBox(height: 16), // Placeholder for low stock items Container( padding: const EdgeInsets.all(24), decoration: BoxDecoration( color: Colors.grey.withOpacity(0.05), borderRadius: BorderRadius.circular(16), ), child: const Center( child: Text('All products are adequately stocked.', style: TextStyle(color: Colors.grey)), ), ), ], ], ), ); } Widget _buildActionCard(BuildContext context, String title, String subtitle, IconData icon, Color color, VoidCallback onTap) { return GestureDetector( onTap: onTap, child: Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: color.withOpacity(0.1), borderRadius: BorderRadius.circular(16), border: Border.all(color: color.withOpacity(0.2)), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(icon, color: color, size: 28), const SizedBox(height: 12), Text(title, style: TextStyle(color: color, fontWeight: FontWeight.bold, fontSize: 16)), const SizedBox(height: 4), Text(subtitle, style: TextStyle(color: color.withOpacity(0.7), fontSize: 12)), ], ), ), ); } }