import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:marking_app/common/model/job/job_report_model.dart';
import 'package:marking_app/utils/easy_refresh/MyEmptyWidget.dart';
import 'package:marking_app/utils/index.dart';

class TopCount extends StatelessWidget {
  final JobReportModel data;
  final String className;
  const TopCount(this.data,this.className,{Key? key}) : super(key: key);

  void showStudentListDialog(
      {required BuildContext context, required String title,required List arr}) {
    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){
                          var item = arr[index];
                          return Container(
                            padding: EdgeInsets.symmetric(vertical: 5.r,horizontal: 15.r),
                            color: index.isOdd?Colors.white:Color(0xFFF0F0F0),
                            child: Text(item,style: TextStyle(fontSize: 12.sp,color: Color(0xFF323232)),),
                          );
                        },itemCount: arr.length,),
                    ):MyEmptyWidget()

                ],
              ),
            ),
          );
        });
  }


  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 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.spaceEvenly,
            children: [
              InkWell(
                onTap: (){
                  showStudentListDialog(context:context,title: '未提交作业学生',arr: data.noAnswerStudentNames);
                },
                child: Container(
                  width: 81.r,
                  padding: EdgeInsets.symmetric(
                      vertical: 10.r, horizontal: 6.r),
                  decoration: BoxDecoration(
                    border: Border.all(
                        width: 1.r,
                        color: Color(0xFF4CC793),
                        style: BorderStyle.solid),
                    borderRadius: BorderRadius.all(Radius.circular(6.r)),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(height: 5.r,),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          Text(
                            data.noAnswerCount.toString(),
                            style: TextStyle(
                                fontSize: 24.sp,
                                color: Color(0xFF4CC793),
                                fontWeight: FontWeight.w600),
                          ),
                          Text(
                            '人',
                            style: TextStyle(
                                fontSize: 16.sp,
                                color: Color(0xFF4CC793),
                                fontWeight: FontWeight.w600),
                          ),
                        ],
                      ),
                      SizedBox(
                        height: 20.r,
                      ),
                      Text(
                        '未提交',
                        style: TextStyle(
                            fontSize: 12.sp, color: Color(0xFF818181)),
                      )
                    ],
                  ),
                ),
              ),
              InkWell(
                onTap: (){
                  showStudentListDialog(context:context,title: '已提交作业学生',arr: data.validStudentNames);
                },
                child: Container(
                  width: 81.r,
                  padding: EdgeInsets.symmetric(
                      vertical: 10.r, horizontal: 6.r),
                  decoration: BoxDecoration(
                    border: Border.all(
                        width: 1.r,
                        color: Color(0xFF4CC793),
                        style: BorderStyle.solid),
                    borderRadius: BorderRadius.all(Radius.circular(6.r)),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(height: 5.r,),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          Text(
                            data.validCount.toString(),
                            style: TextStyle(
                                fontSize: 24.sp,
                                color: Color(0xFF4CC793),
                                fontWeight: FontWeight.w600),
                          ),
                          Text(
                            '人',
                            style: TextStyle(
                                fontSize: 16.sp,
                                color: Color(0xFF4CC793),
                                fontWeight: FontWeight.w600),
                          ),
                        ],
                      ),
                      SizedBox(
                        height: 20.r,
                      ),
                      Text(
                        '已提交',
                        style: TextStyle(
                            fontSize: 12.sp, color: Color(0xFF818181)),
                      )
                    ],
                  ),
                ),
              ),
              InkWell(
                onTap: (){
                  showStudentListDialog(context:context,title: '全对作业学生',arr: data.allCorrectStudentNames);
                },
                child: Container(
                  width: 81.r,
                  padding: EdgeInsets.symmetric(
                      vertical: 10.r, horizontal: 6.r),
                  decoration: BoxDecoration(
                    border: Border.all(
                        width: 1.r,
                        color: Color(0xFF4CC793),
                        style: BorderStyle.solid),
                    borderRadius: BorderRadius.all(Radius.circular(6.r)),
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(height: 5.r,),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          Text(
                            data.allCorrect.toString(),
                            style: TextStyle(
                                fontSize: 24.sp,
                                color: Color(0xFF4CC793),
                                fontWeight: FontWeight.w600),
                          ),
                          Text(
                            '人',
                            style: TextStyle(
                                fontSize: 16.sp,
                                color: Color(0xFF4CC793),
                                fontWeight: FontWeight.w600),
                          ),
                        ],
                      ),
                      SizedBox(
                        height: 20.r,
                      ),
                      Text(
                        '全对',
                        style: TextStyle(
                            fontSize: 12.sp, color: Color(0xFF818181)),
                      )
                    ],
                  ),
                ),
              ),
            ],
          ),
          SizedBox(
            height: 15.r,
          ),
          Padding(
              padding: EdgeInsets.symmetric(horizontal: 15.r),
              child: GridView.builder(
                shrinkWrap: true,
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    childAspectRatio: 150 / 46,
                    crossAxisSpacing: 2.r, //水平子 Widget 之间间距
                    mainAxisSpacing: 2.r, //垂直子 Widget 之间间距
                    crossAxisCount: 2, //一行的 Widget 数量
                  ),
                  itemCount: data.overallTitles.length,
                  itemBuilder: (BuildContext context, index){
                    var item = data.overallTitles[index];
                    Color bgColor = Color(0xFF4CC793);
                    if(item.title == '优'){
                      bgColor = Color(0xFF4CC793);
                    }else if(item.title == '良'){
                      bgColor = Color(0xFFF8700D);
                    }else if(item.title == '中'){
                      bgColor = Color(0xFF4CC7B8);
                    }else if(item.title == '差'){
                      bgColor = Color(0xFFFF6F6F);
                    }
                    return  InkWell(
                      onTap: (){
                        showStudentListDialog(context:context,title:item.title+'等作业学生',arr: item.studentNames);
                      },
                      child: Container(
                        padding: EdgeInsets.symmetric(vertical: 10.r),
                        width: (MediaQuery.of(context).size.width - 55.r) / 2,
                        color: Color(0xFFF5F5F5),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            SizedBox(
                              width: (MediaQuery.of(context).size.width - 55.r)/4 ,
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: [
                                  Container(
                                    width: 28.r,
                                    height: 28.r,
                                    decoration: BoxDecoration(
                                        color: Colors.white,
                                        border: Border.all(
                                            color: bgColor,
                                            width: 1.r,
                                            style: BorderStyle.solid),
                                        borderRadius: BorderRadius.circular(14.r)),
                                    child: Center(
                                        child: Text(
                                          item.title,
                                          style: TextStyle(
                                              color: bgColor, fontSize: 12.r),
                                        )),
                                  ),
                                ],
                              ),
                            ),
                            SizedBox(
                              width: 10.r,
                            ),
                            Text(
                              item.count.toString(),
                              style: TextStyle(
                                  fontSize: 20.sp,
                                  color: Color(0xFF595959)),
                            ),
                            Text(
                              '人',
                              style: TextStyle(
                                  fontSize: 14.sp,
                                  color: Color(0xFF595959)),
                            ),
                          ],
                        ),
                      ),
                    );
                  },
              ),
          ),
        ],
      ),
    );
  }
}
