/// Page: Home Page /// /// Main dashboard screen of the Worker app. /// Displays member card, promotions, and quick action sections. library; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:worker/core/theme/colors.dart'; import 'package:worker/features/home/presentation/providers/member_card_provider.dart'; import 'package:worker/features/home/presentation/providers/promotions_provider.dart'; import 'package:worker/features/home/presentation/widgets/member_card_widget.dart'; import 'package:worker/features/home/presentation/widgets/promotion_slider.dart'; import 'package:worker/features/home/presentation/widgets/quick_action_section.dart'; /// Home Page /// /// Main entry point of the app after login. /// Shows: /// - Member card (Diamond/Platinum/Gold) /// - Promotional banners /// - Quick action sections /// - Bottom navigation /// - Floating action button (Chat) class HomePage extends ConsumerWidget { const HomePage({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { // Watch member card state final memberCardAsync = ref.watch(memberCardProvider); // Watch promotions state final promotionsAsync = ref.watch(promotionsProvider); return Scaffold( backgroundColor: AppColors.grey50, body: RefreshIndicator( onRefresh: () async { // Refresh both member card and promotions await Future.wait([ ref.read(memberCardProvider.notifier).refresh(), ref.read(promotionsProvider.notifier).refresh(), ]); }, child: CustomScrollView( slivers: [ // App Bar const SliverAppBar( floating: true, snap: true, backgroundColor: AppColors.primaryBlue, title: Text('Trang ch�'), centerTitle: true, ), // Member Card Section SliverToBoxAdapter( child: memberCardAsync.when( data: (memberCard) => MemberCardWidget(memberCard: memberCard), loading: () => Container( margin: const EdgeInsets.all(16), height: 200, decoration: BoxDecoration( color: AppColors.grey100, borderRadius: BorderRadius.circular(16), ), child: const Center( child: CircularProgressIndicator(), ), ), error: (error, stack) => Container( margin: const EdgeInsets.all(16), padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: AppColors.danger.withOpacity(0.1), borderRadius: BorderRadius.circular(16), ), child: Column( mainAxisSize: MainAxisSize.min, children: [ const Icon( Icons.error_outline, color: AppColors.danger, size: 48, ), const SizedBox(height: 8), Text( 'Kh�ng th� t�i th� th�nh vi�n', style: TextStyle( color: AppColors.danger, fontWeight: FontWeight.w600, ), ), const SizedBox(height: 4), Text( error.toString(), style: TextStyle( color: AppColors.grey500, fontSize: 12, ), textAlign: TextAlign.center, ), ], ), ), ), ), // Promotions Section SliverToBoxAdapter( child: promotionsAsync.when( data: (promotions) => promotions.isNotEmpty ? Padding( padding: const EdgeInsets.symmetric(vertical: 8), child: PromotionSlider( promotions: promotions, onPromotionTap: (promotion) { // TODO: Navigate to promotion details ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Xem chi ti�t: ${promotion.title}'), ), ); }, ), ) : const SizedBox.shrink(), loading: () => const Padding( padding: EdgeInsets.all(16), child: Center(child: CircularProgressIndicator()), ), error: (error, stack) => const SizedBox.shrink(), ), ), // Quick Action Sections SliverToBoxAdapter( child: Column( children: [ const SizedBox(height: 8), // Products & Cart Section QuickActionSection( title: 'S�n ph�m & Gi� h�ng', actions: [ QuickAction( icon: Icons.grid_view, label: 'S�n ph�m', onTap: () => _showComingSoon(context, 'S�n ph�m'), ), QuickAction( icon: Icons.shopping_cart, label: 'Gi� h�ng', badge: '3', onTap: () => _showComingSoon(context, 'Gi� h�ng'), ), QuickAction( icon: Icons.favorite, label: 'Y�u th�ch', onTap: () => _showComingSoon(context, 'Y�u th�ch'), ), ], ), // Loyalty Section QuickActionSection( title: 'Kh�ch h�ng th�n thi�t', actions: [ QuickAction( icon: Icons.card_giftcard, label: '�i qu�', onTap: () => _showComingSoon(context, '�i qu�'), ), QuickAction( icon: Icons.history, label: 'L�ch s� i�m', onTap: () => _showComingSoon(context, 'L�ch s� i�m'), ), QuickAction( icon: Icons.person_add, label: 'Gi�i thi�u b�n', onTap: () => _showComingSoon(context, 'Gi�i thi�u b�n'), ), ], ), // Quote Requests Section QuickActionSection( title: 'Y�u c�u b�o gi� & b�o gi�', actions: [ QuickAction( icon: Icons.description, label: 'Y�u c�u b�o gi�', onTap: () => _showComingSoon(context, 'Y�u c�u b�o gi�'), ), QuickAction( icon: Icons.receipt_long, label: 'B�o gi�', onTap: () => _showComingSoon(context, 'B�o gi�'), ), ], ), // Orders & Payments Section QuickActionSection( title: '�n h�ng & thanh to�n', actions: [ QuickAction( icon: Icons.inventory_2, label: '�n h�ng', onTap: () => _showComingSoon(context, '�n h�ng'), ), QuickAction( icon: Icons.payment, label: 'Thanh to�n', onTap: () => _showComingSoon(context, 'Thanh to�n'), ), ], ), // Sample Houses & News Section QuickActionSection( title: 'Nh� m�u, d� �n & tin t�c', actions: [ QuickAction( icon: Icons.home_work, label: 'Nh� m�u', onTap: () => _showComingSoon(context, 'Nh� m�u'), ), QuickAction( icon: Icons.business, label: 'ng k� d� �n', onTap: () => _showComingSoon(context, 'ng k� d� �n'), ), QuickAction( icon: Icons.article, label: 'Tin t�c', onTap: () => _showComingSoon(context, 'Tin t�c'), ), ], ), // Bottom Padding (for FAB clearance) const SizedBox(height: 80), ], ), ), ], ), ), // Floating Action Button (Chat) floatingActionButton: FloatingActionButton( onPressed: () => _showComingSoon(context, 'Chat'), backgroundColor: AppColors.accentCyan, child: const Icon(Icons.chat_bubble), ), // Bottom Navigation Bar bottomNavigationBar: BottomNavigationBar( type: BottomNavigationBarType.fixed, currentIndex: 0, items: const [ BottomNavigationBarItem( icon: Icon(Icons.home), label: 'Trang ch�', ), BottomNavigationBarItem( icon: Icon(Icons.loyalty), label: 'H�i vi�n', ), BottomNavigationBarItem( icon: Icon(Icons.local_offer), label: 'Khuy�n m�i', ), BottomNavigationBarItem( icon: Badge( label: Text('5'), child: Icon(Icons.notifications), ), label: 'Th�ng b�o', ), BottomNavigationBarItem( icon: Icon(Icons.account_circle), label: 'C�i �t', ), ], onTap: (index) { // TODO: Implement navigation final labels = [ 'Trang ch�', 'H�i vi�n', 'Khuy�n m�i', 'Th�ng b�o', 'C�i �t' ]; _showComingSoon(context, labels[index]); }, ), ); } /// Show coming soon message void _showComingSoon(BuildContext context, String feature) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('$feature - S�p ra m�t'), duration: const Duration(seconds: 1), ), ); } }