import 'package:flutter/material.dart';
import '../../../../core/theme/app_colors.dart';
import '../../../../core/theme/app_text_styles.dart';
import '../../../../core/theme/app_radius.dart';
import '../../../../core/utils/formatters.dart';
import '../../../../core/widgets/fs_badge.dart';
import '../../data/models/user_stats_model.dart';

class RecentAttemptsList extends StatelessWidget {
  final List<QuizAttemptModel> attempts;

  const RecentAttemptsList({super.key, required this.attempts});

  @override
  Widget build(BuildContext context) {
    if (attempts.isEmpty) {
      return Container(
        padding: const EdgeInsets.all(24),
        alignment: Alignment.center,
        child: Text(
          'No quiz attempts yet.\nStart practicing to see your results!',
          style: AppTextStyles.bodySmall.copyWith(color: AppColors.textTertiary),
          textAlign: TextAlign.center,
        ),
      );
    }

    return Column(
      children: attempts.map((a) {
        final score = a.score ?? 0;
        final badgeVariant = score >= 70
            ? FSBadgeVariant.green
            : score >= 40
                ? FSBadgeVariant.orange
                : FSBadgeVariant.red;

        return Container(
          padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
          decoration: BoxDecoration(
            border: Border(
              bottom: BorderSide(color: AppColors.border.withOpacity(0.5)),
            ),
          ),
          child: Row(
            children: [
              Expanded(
                flex: 3,
                child: Text(
                  Formatters.date(a.startedAt),
                  style: AppTextStyles.bodySmall,
                ),
              ),
              Expanded(
                flex: 2,
                child: FSBadge(
                  text: '$score%',
                  variant: badgeVariant,
                ),
              ),
              Expanded(
                flex: 2,
                child: Text(
                  '${a.correctAnswers ?? 0}/${a.totalQuestions ?? 0}',
                  style: AppTextStyles.bodySmall,
                  textAlign: TextAlign.center,
                ),
              ),
              Expanded(
                flex: 2,
                child: Text(
                  a.status,
                  style: AppTextStyles.caption,
                  textAlign: TextAlign.end,
                ),
              ),
            ],
          ),
        );
      }).toList(),
    );
  }
}