import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:xp_dashboard/src/widgets/stats_header.dart';
import 'package:xp_models/xp_models.dart';

void main() {
  group('StatsHeader Widget Tests', () {
    testWidgets('displays stats correctly', (WidgetTester tester) async {
      // Create test data
      final stats = DashboardStats(
        today: TodayStats(
          level: 5,
          xp: 1250,
          focusTime: 7200, // 2 hours
          meetingTime: 3600, // 1 hour
          focusSessions: 3,
        ),
        streaks: StreakStats(
          currentStreak: 7,
          longestStreak: 15,
        ),
        recentActivity: [],
        timestamp: DateTime.now(),
      );

      // Build the widget
      await tester.pumpWidget(
        MaterialApp(
          home: Scaffold(
            body: StatsHeader(stats: stats),
          ),
        ),
      );

      // Verify the stats are displayed
      expect(find.text('5'), findsOneWidget); // Level
      expect(find.text('1.3K'), findsOneWidget); // XP formatted
      expect(find.text('7'), findsOneWidget); // Streak
      expect(find.text('Level'), findsOneWidget);
      expect(find.text('XP'), findsOneWidget);
      expect(find.text('Streak'), findsOneWidget);
    });

    testWidgets('handles null stats gracefully', (WidgetTester tester) async {
      await tester.pumpWidget(
        const MaterialApp(
          home: Scaffold(
            body: StatsHeader(stats: null),
          ),
        ),
      );

      // Should render empty container
      expect(find.byType(SizedBox), findsOneWidget);
    });

    testWidgets('formats large numbers correctly', (WidgetTester tester) async {
      final stats = DashboardStats(
        today: TodayStats(
          level: 50,
          xp: 1500000, // 1.5M
          focusTime: 0,
          meetingTime: 0,
          focusSessions: 0,
        ),
        streaks: StreakStats(
          currentStreak: 100,
          longestStreak: 200,
        ),
        recentActivity: [],
        timestamp: DateTime.now(),
      );

      await tester.pumpWidget(
        MaterialApp(
          home: Scaffold(
            body: StatsHeader(stats: stats),
          ),
        ),
      );

      expect(find.text('1.5M'), findsOneWidget); // XP formatted as millions
      expect(find.text('50'), findsOneWidget); // Level
      expect(find.text('100'), findsOneWidget); // Streak
    });
  });
}
