import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:functional_widget_annotation/functional_widget_annotation.dart';
import 'package:making_school_asignment_app/common/job/homework_details.dart';
import 'package:making_school_asignment_app/page/global_widget/MyEmptyWidget.dart';
import 'package:making_school_asignment_app/page/global_widget/show_student_list.dart';
import 'package:making_school_asignment_app/page/home_page/children/quick_data_check/quick_data_check_state.dart';

part 'top_count.g.dart';

class TopCount extends StatelessWidget {
  final CountData data;
  final String className;
  final String jobId;
  final int subject;

  const TopCount(this.data, this.className, this.jobId, this.subject,{Key? key}) : super(key: key);

  void showStudentListDialog({required BuildContext context, required String title, required List<Students> students}) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return ShowStudentList(
          title: title,
          studentList: students,
          homeworkId: jobId,
          subject: subject,
        );
      },
    );
    /*showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            // insetPadding: EdgeInsets.symmetric(vertical: 20.r,horizontal: 20.r),
            contentPadding: EdgeInsets.all(20.r),
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(15.r))),
            content: SizedBox(
              width: MediaQuery.of(context).size.width * 0.7,
              height: MediaQuery.of(context).size.height * 0.7,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Center(
                    child: Text(
                      className + title,
                      style: TextStyle(fontSize: 15.sp, color: Color(0xFF3C3C3C), fontWeight: FontWeight.w500),
                    ),
                  ),
                  SizedBox(
                    height: 5.r,
                  ),
                  SizedBox(
                    height: 15.r,
                  ),
                  arr.length > 0
                      ? Expanded(
                          child: ListView.builder(
                            shrinkWrap: true,
                            itemBuilder: (context, index) {
                              AnswerOkStudents item = arr[index];
                              return InkWell(
                                onTap: () {
                                  */ /*RouterManager.router.navigateTo(
                                    context,
                                    RouterManager.quickCheckPersonalPath + '?jobId=$jobId&studentId=${item.id}',
                                    transition: getTransition(),
                                  );*/ /*
                                },
                                child: Container(
                                  padding: EdgeInsets.symmetric(vertical: 5.r, horizontal: 15.r),
                                  color: index.isOdd ? Colors.white : Color(0xFFF0F0F0),
                                  child: Text(
                                    item.name,
                                    style: TextStyle(fontSize: 12.sp, color: Color(0xFF323232)),
                                  ),
                                ),
                              );
                            },
                            itemCount: arr.length,
                          ),
                        )
                      : const MyEmptyWidget()
                ],
              ),
            ),
          );
        });*/
  }

  @override
  Widget build(BuildContext context) {
    double leftWidth = (MediaQuery.of(context).size.width - 40.r) * 0.7 / 3;
    double rightWidth = (MediaQuery.of(context).size.width - 40.r) * 0.3 / 2;
    return Container(
      padding: EdgeInsets.symmetric(vertical: 20.r, horizontal: 20.r),
      margin: EdgeInsets.symmetric(vertical: 10.r, horizontal: 10.r),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(6.r)),
      ),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              InkWell(
                onTap: () {
                  showStudentListDialog(context: context, title: '未提交作业学生', students: data.noAnswerStudents!);
                },
                child: leftContainer(context, count: data.noAnswerCount!, name: '未提交', nameColor: Color(0xFF10978E), bgColor: Color(0xFFE8F8F7)),
              ),
              InkWell(
                onTap: () {
                  showStudentListDialog(context: context, title: '已提交作业学生', students: data.studentSubmitStudents!);
                },
                child: leftContainer(context, count: data.studentSubmitCount!, name: '已提交', nameColor: Color(0xFFEF5614), bgColor: Color(0xFFFCEFEA)),
              ),
              InkWell(
                onTap: () {
                  showStudentListDialog(context: context, title: '全对作业学生', students: data.allCorrectStudents!);
                },
                child: leftContainer(context, count: data.allCorrect!, name: '全对', nameColor: Color(0xFF8C68FF), bgColor: Color(0xFFE9EBFD)),
              ),

            ],
          ),
          SizedBox(height: 15.r,),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              InkWell(
                onTap: () {
                  showStudentListDialog(context: context, title: '优等作业学生', students: data.levelOneStudents!);
                },
                child: rightContainer(
                  context,
                  count: data.levelOneCount!,
                  bgColor: const Color(0xFFE8F8F7),
                  nameColor: const Color(0xFF009254),
                  borderColor: const Color(0xFF4CC793),
                  name: '优',
                ),
              ),
              InkWell(
                onTap: () {
                  showStudentListDialog(context: context, title: '良等作业学生', students: data.levelTwoStudents!);
                },
                child: rightContainer(context,count: data.levelTwoCount!, bgColor: Color(0xFFFEF9F6), nameColor: Color(0xFFE87F0B), borderColor: const Color(0xFFFF9F46), name: '良'),
              )
            ],
          ),
          SizedBox(height: 10.r,),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              InkWell(
                onTap: () {
                  showStudentListDialog(context: context, title: '中等作业学生', students: data.levelThreeStudents!);
                },
                child: rightContainer(context,count: data.levelThreeCount!, bgColor: Color(0xFFFFF6F6), nameColor: Color(0xFFFF7474), borderColor: const Color(0xFFFFCACA),name: '中'),
              ),
              InkWell(
                onTap: () {
                  showStudentListDialog(context: context, title: '差等作业学生', students: data.levelFourStudents!);
                },
                child: rightContainer(context,count: data.levelFourCount!, bgColor: Color(0xFFECEFEF), nameColor: Color(0xFF5C5B59), borderColor: const Color(0xFFD8D8D8),name: '差'),
              )
            ],
          ),
      /*    Container(
            height: 92.r,
            width: rightWidth,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Expanded(
                    child: InkWell(
                      onTap: () {
                        showStudentListDialog(context: context, title: '优等作业学生', students: data.levelOneStudents!);
                      },
                      child: rightContainer(
                        count: data.levelOneCount!,
                        bgColor: Color(0xFF56FFB8),
                        nameColor: Color(0xFF009254),
                        name: '优',
                      ),
                    )),
                Expanded(
                    child: InkWell(
                      onTap: () {
                        showStudentListDialog(context: context, title: '中等作业学生', students: data.levelThreeStudents!);
                      },
                      child: rightContainer(count: data.levelThreeCount!, bgColor: Color(0xFFD3FF93), nameColor: Color(0xFF3F6605), name: '中'),
                    )),
              ],
            ),
          ),
          Container(
            height: 92.r,
            width: rightWidth,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Expanded(
                    child: InkWell(
                      onTap: () {
                        showStudentListDialog(context: context, title: '良等作业学生', students: data.levelTwoStudents!);
                      },
                      child: rightContainer(context,count: data.levelTwoCount!, bgColor: Color(0xFFFFC38C), nameColor: Color(0xFFD36500), name: '良'),
                    )),
                Expanded(
                    child: InkWell(
                      onTap: () {
                        showStudentListDialog(context: context, title: '差等作业学生', students: data.levelFourStudents!);
                      },
                      child: rightContainer(context,count: data.levelFourCount!, bgColor: Color(0xFFFF9D94), nameColor: Color(0xFFD12616), name: '差'),
                    )),
              ],
            ),
          )*/
        ],
      ),
    );
  }
}

@swidget
Widget leftContainer(context, {required int count, required String name, required Color nameColor, required Color bgColor}) {
  double leftWidth = (MediaQuery.of(context).size.width - 100.r) / 3;
  return Container(
    width: leftWidth,
    height: 108.r,
    padding: EdgeInsets.symmetric(vertical: 10.r, horizontal: 6.r),
    decoration: BoxDecoration(
      color: bgColor,
      borderRadius: BorderRadius.all(Radius.circular(10.r)),
    ),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        SizedBox(
          height: 5.r,
        ),
        Row(
          crossAxisAlignment: CrossAxisAlignment.end,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              count.toString(),
              style: TextStyle(fontSize: 18.sp, color: Color(0xFF595959), fontWeight: FontWeight.w600),
            ),
            Text(
              '人',
              style: TextStyle(fontSize: 10.sp, color: Color(0xFF595959), fontWeight: FontWeight.w600),
            ),
          ],
        ),
        SizedBox(
          height: 30.r,
        ),
        Text(
          name,
          style: TextStyle(fontSize: 12.sp, color: nameColor, fontWeight: FontWeight.w500),
        )
      ],
    ),
  );
}

@swidget
Widget rightContainer(context,{required int count, required Color bgColor, required Color nameColor, required Color borderColor,required String name}) {
  return Container(
    width: (MediaQuery.of(context).size.width - 80.r) / 2,
    height: 48.r,
    decoration: BoxDecoration(
      color: bgColor,
      borderRadius: BorderRadius.all(Radius.circular(10.r)),
      border: Border.all(color: borderColor,width: 1.r),
    ),
    child: Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        SizedBox(width: 20.r,),
Expanded(child: Row(
  crossAxisAlignment: CrossAxisAlignment.center,
  children: [
    Text(
      count.toString(),
      style: TextStyle(fontSize: 24.sp, color: const Color(0xFF505251), fontWeight: FontWeight.w300),
    ),
    Padding(
      padding: EdgeInsets.only(top: 3.r),
      child: Text(
        '人',
        style: TextStyle(fontSize: 10.sp, color: const Color(0xFF505251), fontWeight: FontWeight.w300),
      ),
    ),
  ],
)),


        Text(
          name,
          style: TextStyle(fontSize: 12.sp, color: nameColor, fontWeight: FontWeight.w600),
        ),
        SizedBox(width: 20.r,),
      ],
    ),
  );
}
