import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../../models/task_log_model.dart'; import '../../services/task_log_service.dart'; import '../../providers/auth_provider.dart'; import '../../widgets/log_card.dart'; import '../log_form_screen.dart'; class TodayLogsTab extends StatelessWidget { const TodayLogsTab({super.key}); @override Widget build(BuildContext context) { final userId = context.watch().user?.uid; final userName = context.watch().user?.name ?? "Team Member"; final service = context.read(); final now = DateTime.now(); final startOfDay = DateTime(now.year, now.month, now.day); final endOfDay = DateTime(now.year, now.month, now.day, 23, 59, 59); if (userId == null) { return const Center(child: Text("User not logged in.")); } return Scaffold( backgroundColor: const Color(0xFFF8FAFC), body: StreamBuilder>( stream: service.getTaskLogs( userId: userId, from: startOfDay, to: endOfDay, ), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const Center(child: CircularProgressIndicator()); } final logs = snapshot.data ?? []; return CustomScrollView( slivers: [ SliverPadding( padding: const EdgeInsets.fromLTRB(20, 20, 20, 10), sliver: SliverToBoxAdapter( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "Hello, $userName 👋", style: const TextStyle(fontSize: 14, color: Color(0xFF64748B), fontWeight: FontWeight.w500), ), const Text( "Today's Progress", style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold, color: Color(0xFF1E293B)), ), const SizedBox(height: 20), _buildStatsHeader(logs), const SizedBox(height: 24), const Row( children: [ Icon(Icons.history_rounded, size: 18, color: Color(0xFF64748B)), SizedBox(width: 8), Text( "Recent Activity", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Color(0xFF475569)), ), ], ), ], ), ), ), if (logs.isEmpty) SliverFillRemaining( hasScrollBody: false, child: Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ Icon(Icons.rocket_launch_outlined, size: 100, color: Colors.grey.shade200), const SizedBox(height: 16), Text( "Ready to log your first task?", style: TextStyle(color: Colors.grey.shade500, fontSize: 13, fontWeight: FontWeight.w500), ), const SizedBox(height: 24), ElevatedButton.icon( onPressed: () => Navigator.push( context, MaterialPageRoute(builder: (_) => const LogFormScreen()) ), icon: const Icon(Icons.add_rounded), label: const Text("START LOGGING"), style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFF6366F1), padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 14), minimumSize: const Size(200, 50), ), ), ], ), ), ) else SliverPadding( padding: const EdgeInsets.all(20), sliver: SliverList( delegate: SliverChildBuilderDelegate( (context, index) => LogCard(log: logs[index], canEdit: true), childCount: logs.length, ), ), ), ], ); }, ), floatingActionButton: FloatingActionButton.extended( heroTag: "today_logs_fab", backgroundColor: const Color(0xFF6366F1), onPressed: () => Navigator.push( context, MaterialPageRoute(builder: (_) => const LogFormScreen()) ), icon: const Icon(Icons.add_rounded, color: Colors.white), label: const Text("LOG WORK", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)), ), ); } Widget _buildStatsHeader(List logs) { int total = logs.length; int done = logs.where((l) => l.status == 'done').length; double progress = total == 0 ? 0 : done / total; return Container( padding: const EdgeInsets.all(24), decoration: BoxDecoration( gradient: const LinearGradient( colors: [Color(0xFF6366F1), Color(0xFF4F46E5)], begin: Alignment.topLeft, end: Alignment.bottomRight, ), borderRadius: BorderRadius.circular(32), boxShadow: [ BoxShadow( color: const Color(0xFF6366F1).withOpacity(0.3), blurRadius: 15, offset: const Offset(0, 8), ), ], ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ const Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "DAILY GOAL", style: TextStyle(color: Colors.white70, fontSize: 10, fontWeight: FontWeight.bold, letterSpacing: 1.2), ), SizedBox(height: 4), Text( "Finish Tasks 🚀", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 18), ), ], ), Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( color: Colors.white.withOpacity(0.2), shape: BoxShape.circle, ), child: const Icon(Icons.flash_on_rounded, color: Colors.yellow, size: 24), ), ], ), const SizedBox(height: 24), Row( children: [ Text( "${(progress * 100).toInt()}% COMPLETED", style: const TextStyle(color: Colors.white, fontSize: 12, fontWeight: FontWeight.bold), ), const Spacer(), Text( "$done/$total Tasks", style: const TextStyle(color: Colors.white70, fontSize: 12, fontWeight: FontWeight.w500), ), ], ), const SizedBox(height: 10), ClipRRect( borderRadius: BorderRadius.circular(10), child: LinearProgressIndicator( value: progress, minHeight: 10, backgroundColor: Colors.white.withOpacity(0.2), valueColor: const AlwaysStoppedAnimation(Colors.white), ), ), ], ), ); } }