import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:google_fonts/google_fonts.dart'; import '../../models/cycle_entry.dart'; import '../../providers/user_provider.dart'; import '../../theme/app_theme.dart'; import 'package:uuid/uuid.dart'; class LogScreen extends ConsumerStatefulWidget { const LogScreen({super.key}); @override ConsumerState createState() => _LogScreenState(); } class _LogScreenState extends ConsumerState { bool _isPeriodDay = false; FlowIntensity? _flowIntensity; MoodLevel? _mood; int _energyLevel = 3; int _crampIntensity = 0; bool _hasHeadache = false; bool _hasBloating = false; bool _hasBreastTenderness = false; bool _hasFatigue = false; bool _hasAcne = false; final TextEditingController _notesController = TextEditingController(); @override void dispose() { _notesController.dispose(); super.dispose(); } Future _saveEntry() async { final entry = CycleEntry( id: const Uuid().v4(), date: DateTime.now(), isPeriodDay: _isPeriodDay, flowIntensity: _isPeriodDay ? _flowIntensity : null, mood: _mood, energyLevel: _energyLevel, crampIntensity: _crampIntensity > 0 ? _crampIntensity : null, hasHeadache: _hasHeadache, hasBloating: _hasBloating, hasBreastTenderness: _hasBreastTenderness, hasFatigue: _hasFatigue, hasAcne: _hasAcne, notes: _notesController.text.isNotEmpty ? _notesController.text : null, createdAt: DateTime.now(), updatedAt: DateTime.now(), ); await ref.read(cycleEntriesProvider.notifier).addEntry(entry); if (mounted) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Entry saved!', style: GoogleFonts.outfit()), backgroundColor: AppColors.sageGreen, behavior: SnackBarBehavior.floating, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), ), ); _resetForm(); } } void _resetForm() { setState(() { _isPeriodDay = false; _flowIntensity = null; _mood = null; _energyLevel = 3; _crampIntensity = 0; _hasHeadache = false; _hasBloating = false; _hasBreastTenderness = false; _hasFatigue = false; _hasAcne = false; _notesController.clear(); }); } @override Widget build(BuildContext context) { return SafeArea( child: SingleChildScrollView( padding: const EdgeInsets.all(20), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // Header Text( 'How are you feeling?', style: GoogleFonts.outfit( fontSize: 28, fontWeight: FontWeight.w600, color: AppColors.charcoal, ), ), Text( _formatDate(DateTime.now()), style: GoogleFonts.outfit( fontSize: 14, color: AppColors.warmGray, ), ), const SizedBox(height: 24), // Period Toggle _buildSectionCard( title: 'Period', child: Row( children: [ Expanded( child: Text( 'Is today a period day?', style: GoogleFonts.outfit( fontSize: 16, color: AppColors.charcoal, ), ), ), Switch( value: _isPeriodDay, onChanged: (value) => setState(() => _isPeriodDay = value), activeColor: AppColors.menstrualPhase, ), ], ), ), // Flow Intensity (only if period day) if (_isPeriodDay) ...[ const SizedBox(height: 16), _buildSectionCard( title: 'Flow Intensity', child: Row( children: FlowIntensity.values.map((flow) { final isSelected = _flowIntensity == flow; return Expanded( child: GestureDetector( onTap: () => setState(() => _flowIntensity = flow), child: Container( margin: const EdgeInsets.symmetric(horizontal: 4), padding: const EdgeInsets.symmetric(vertical: 12), decoration: BoxDecoration( color: isSelected ? AppColors.menstrualPhase.withOpacity(0.2) : AppColors.lightGray.withOpacity(0.1), borderRadius: BorderRadius.circular(10), border: isSelected ? Border.all(color: AppColors.menstrualPhase) : null, ), child: Column( children: [ Icon( Icons.water_drop, color: isSelected ? AppColors.menstrualPhase : AppColors.warmGray, size: 20, ), const SizedBox(height: 4), Text( flow.label, style: GoogleFonts.outfit( fontSize: 11, color: isSelected ? AppColors.menstrualPhase : AppColors.warmGray, ), ), ], ), ), ), ); }).toList(), ), ), ], const SizedBox(height: 16), // Mood _buildSectionCard( title: 'Mood', child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: MoodLevel.values.map((mood) { final isSelected = _mood == mood; return GestureDetector( onTap: () => setState(() => _mood = mood), child: Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( color: isSelected ? AppColors.softGold.withOpacity(0.2) : Colors.transparent, borderRadius: BorderRadius.circular(12), border: isSelected ? Border.all(color: AppColors.softGold) : null, ), child: Column( children: [ Text( mood.emoji, style: TextStyle( fontSize: isSelected ? 32 : 28, ), ), const SizedBox(height: 4), Text( mood.label, style: GoogleFonts.outfit( fontSize: 10, color: isSelected ? AppColors.softGold : AppColors.warmGray, ), ), ], ), ), ); }).toList(), ), ), const SizedBox(height: 16), // Energy Level _buildSectionCard( title: 'Energy Level', child: Column( children: [ Row( children: [ const Icon(Icons.battery_1_bar, color: AppColors.warmGray), Expanded( child: Slider( value: _energyLevel.toDouble(), min: 1, max: 5, divisions: 4, onChanged: (value) { setState(() => _energyLevel = value.round()); }, ), ), const Icon(Icons.battery_full, color: AppColors.sageGreen), ], ), Text( _getEnergyLabel(_energyLevel), style: GoogleFonts.outfit( fontSize: 13, color: AppColors.warmGray, ), ), ], ), ), const SizedBox(height: 16), // Symptoms _buildSectionCard( title: 'Symptoms', child: Column( children: [ // Cramps Slider Row( children: [ SizedBox( width: 80, child: Text( 'Cramps', style: GoogleFonts.outfit( fontSize: 14, color: AppColors.charcoal, ), ), ), Expanded( child: Slider( value: _crampIntensity.toDouble(), min: 0, max: 5, divisions: 5, activeColor: AppColors.rose, onChanged: (value) { setState(() => _crampIntensity = value.round()); }, ), ), SizedBox( width: 40, child: Text( _crampIntensity == 0 ? 'None' : '$_crampIntensity/5', style: GoogleFonts.outfit( fontSize: 12, color: AppColors.warmGray, ), ), ), ], ), const SizedBox(height: 12), // Symptom Toggles Wrap( spacing: 8, runSpacing: 8, children: [ _buildSymptomChip('Headache', _hasHeadache, (v) => setState(() => _hasHeadache = v)), _buildSymptomChip('Bloating', _hasBloating, (v) => setState(() => _hasBloating = v)), _buildSymptomChip('Breast Tenderness', _hasBreastTenderness, (v) => setState(() => _hasBreastTenderness = v)), _buildSymptomChip('Fatigue', _hasFatigue, (v) => setState(() => _hasFatigue = v)), _buildSymptomChip('Acne', _hasAcne, (v) => setState(() => _hasAcne = v)), ], ), ], ), ), const SizedBox(height: 16), // Notes _buildSectionCard( title: 'Notes', child: TextField( controller: _notesController, maxLines: 3, decoration: InputDecoration( hintText: 'Add any notes about how you\'re feeling...', hintStyle: GoogleFonts.outfit( color: AppColors.lightGray, fontSize: 14, ), border: InputBorder.none, ), style: GoogleFonts.outfit( fontSize: 14, color: AppColors.charcoal, ), ), ), const SizedBox(height: 24), // Save Button SizedBox( width: double.infinity, child: ElevatedButton( onPressed: _saveEntry, child: const Text('Save Entry'), ), ), const SizedBox(height: 40), ], ), ), ); } Widget _buildSectionCard({required String title, required Widget child}) { return Container( width: double.infinity, padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16), boxShadow: [ BoxShadow( color: AppColors.charcoal.withOpacity(0.05), blurRadius: 10, offset: const Offset(0, 4), ), ], ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( title, style: GoogleFonts.outfit( fontSize: 16, fontWeight: FontWeight.w600, color: AppColors.charcoal, ), ), const SizedBox(height: 12), child, ], ), ); } Widget _buildSymptomChip(String label, bool isSelected, ValueChanged onChanged) { return GestureDetector( onTap: () => onChanged(!isSelected), child: Container( padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8), decoration: BoxDecoration( color: isSelected ? AppColors.lavender.withOpacity(0.3) : AppColors.lightGray.withOpacity(0.1), borderRadius: BorderRadius.circular(20), border: isSelected ? Border.all(color: AppColors.lavender) : null, ), child: Text( label, style: GoogleFonts.outfit( fontSize: 13, color: isSelected ? AppColors.ovulationPhase : AppColors.warmGray, fontWeight: isSelected ? FontWeight.w500 : FontWeight.w400, ), ), ), ); } String _formatDate(DateTime date) { const months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; return '${days[date.weekday - 1]}, ${months[date.month - 1]} ${date.day}'; } String _getEnergyLabel(int level) { switch (level) { case 1: return 'Very Low'; case 2: return 'Low'; case 3: return 'Normal'; case 4: return 'Good'; case 5: return 'Excellent'; default: return 'Normal'; } } }