import 'package:english_learning/core/utils/styles/theme.dart';
import 'package:english_learning/core/widgets/custom_button.dart';
import 'package:english_learning/features/learning/modules/level/models/level_model.dart';
import 'package:english_learning/features/learning/modules/material/screens/material_screen.dart';
import 'package:flutter/material.dart';

class LevelCard extends StatelessWidget {
  final Level level;
  final bool isAllowed;
  final int score;
  final bool isCompleted;

  const LevelCard({
    super.key,
    required this.level,
    required this.isAllowed,
    required this.score,
    required this.isCompleted,
  });

  @override
  Widget build(BuildContext context) {
    return Card(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12),
      ),
      elevation: 0,
      child: Container(
        height: MediaQuery.of(context).size.height * 0.6,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(12),
          gradient: isAllowed
              ? AppColors.gradientTheme
              : const LinearGradient(
                  colors: [
                    AppColors.disableColor,
                    AppColors.disableColor,
                  ],
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                ),
        ),
        child: Stack(
          children: [
            if (isAllowed && score > 0)
              Positioned(
                right: -23,
                bottom: 4,
                child: Image.asset(
                  'lib/features/learning/modules/level/assets/images/Icon_Complete.png',
                  width: 110,
                ),
              ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  // Level Header
                  Container(
                    padding: const EdgeInsets.symmetric(
                      vertical: 4,
                      horizontal: 8,
                    ),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(8),
                      border: Border.all(
                        color: AppColors.whiteColor,
                        width: 1.5,
                      ),
                    ),
                    child: Row(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Text('LEVEL',
                            style: AppTextStyles.whiteTextStyle.copyWith(
                              fontWeight: FontWeight.w900,
                              fontSize: 16,
                            )),
                        const SizedBox(width: 4),
                        Container(
                          decoration: BoxDecoration(
                            color: AppColors.whiteColor,
                            borderRadius: BorderRadius.circular(6),
                          ),
                          child: Padding(
                            padding: const EdgeInsets.symmetric(
                              horizontal: 12.0,
                              vertical: 2.0,
                            ),
                            child: Text(
                              level.nameLevel.replaceAll('Level ', ''),
                              style: isAllowed
                                  ? AppTextStyles.blueTextStyle.copyWith(
                                      fontWeight: FontWeight.w900,
                                      fontSize: 16,
                                    )
                                  : AppTextStyles.disableTextStyle.copyWith(
                                      fontWeight: FontWeight.w900,
                                      fontSize: 16,
                                    ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  const SizedBox(height: 6),
                  // Score Display
                  Text(
                    // 'Score ${level.score}/100',
                    'Score $score/100',
                    style: AppTextStyles.whiteTextStyle.copyWith(
                      fontWeight: FontWeight.w900,
                      fontSize: 12,
                    ),
                  ),
                  const Spacer(), // Learn Now Button
                  Align(
                    alignment: Alignment.bottomCenter,
                    child: Padding(
                      padding: const EdgeInsets.symmetric(horizontal: 8.0),
                      child: CustomButton(
                        text: isAllowed ? 'Learn Now' : 'Locked',
                        textStyle:
                            isAllowed ? null : AppTextStyles.disableTextStyle,
                        width: double.infinity,
                        height: 36,
                        color: isAllowed
                            ? AppColors.yellowButtonColor
                            : AppColors.cardButtonColor,
                        onPressed: isAllowed
                            ? () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                    builder: (context) => MaterialScreen(
                                      levelId: level.idLevel,
                                      topicId: level.idTopic,
                                      topicTitle: level.nameTopic,
                                    ),
                                  ),
                                );
                              }
                            : () {},
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
