import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:lucide_icons/lucide_icons.dart'; import '../../providers/sake_list_provider.dart'; class ActivityStats extends ConsumerWidget { const ActivityStats({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final allSakeAsync = ref.watch(sakeListProvider); return allSakeAsync.when( data: (sakes) { final totalSakes = sakes.length; final favoriteCount = sakes.where((s) => s.userData.isFavorite).length; // Recording Days final dates = sakes.map((s) { final d = s.metadata.createdAt; return DateTime(d.year, d.month, d.day); }).toSet(); final recordingDays = dates.length; // Avg Price int totalPrice = 0; int priceCount = 0; for (var s in sakes) { if (s.userData.price != null && s.userData.price! > 0) { totalPrice += s.userData.price!; priceCount++; } } final avgPrice = priceCount > 0 ? (totalPrice / priceCount).round() : 0; return Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: Theme.of(context).cardColor, borderRadius: BorderRadius.circular(16), border: Border.all( color: Theme.of(context).dividerColor.withValues(alpha: 0.1), ), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'あなたの活動深度', style: Theme.of(context).textTheme.titleSmall?.copyWith( fontWeight: FontWeight.bold, ), ), const SizedBox(height: 16), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ _buildStatItem(context, '総登録数', '$totalSakes本', LucideIcons.wine), _buildStatItem(context, 'お気に入り', '$favoriteCount本', LucideIcons.heart), _buildStatItem(context, '撮影日数', '$recordingDays日', LucideIcons.calendar), _buildStatItem(context, '平均価格', '¥$avgPrice', LucideIcons.banknote), ], ), ], ), ); }, loading: () => const SizedBox.shrink(), error: (_, __) => const SizedBox.shrink(), ); } Widget _buildStatItem(BuildContext context, String label, String value, IconData icon) { return Column( children: [ Icon(icon, size: 20, color: Colors.grey[400]), const SizedBox(height: 8), Text( value, style: TextStyle( fontSize: 14, fontWeight: FontWeight.w900, color: Theme.of(context).colorScheme.onSurface, ), ), const SizedBox(height: 4), Text( label, style: TextStyle(fontSize: 10, color: Colors.grey[600]), ), ], ); } }