import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:marking_app/common/model/job/job_data_report.dart';
import 'package:marking_app/pages/homework_correction/widget/quick_student_data_table.dart';

class QuickDataCheckBottom extends StatefulWidget {
  final int jobId;
  final JobDataReport? jobData;
  const QuickDataCheckBottom({Key? key,required this.jobId,required this.jobData}) : super(key: key);

  @override
  State<QuickDataCheckBottom> createState() => _QuickDataCheckBottomState();
}

class _QuickDataCheckBottomState extends State<QuickDataCheckBottom> {
  List<StudentDetails> showList = [];
  List<StudentDetails> followList = [];
  void initState() {
    super.initState();
    showList =widget.jobData!.studentDetails;
    widget.jobData!.studentDetails.forEach((e) {
      if(e.readLevel == 1){
        followList.add(e);
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return  Container(
      padding: EdgeInsets.symmetric(
          vertical: 10.r, horizontal: 10.r),
      margin: EdgeInsets.symmetric(
          vertical: 10.r, horizontal: 14.r),
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius:
          BorderRadius.all(Radius.circular(6.r))),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              InkWell(
                onTap: (){
                  if (widget.jobData == null) return;
                  if (!widget.jobData!.sortType) {
                    widget.jobData!.studentDetails.sort((a, b) {
                      int num1 =
                          a.kgValidRate + a.zgValidRate;
                      int num2 =
                          b.kgValidRate + b.zgValidRate;
                      return num2.compareTo(num1);
                    });
                  } else {
                    widget.jobData!.studentDetails.sort((a, b) {
                      int num1 =
                          a.kgValidRate + a.zgValidRate;
                      int num2 =
                          b.kgValidRate + b.zgValidRate;
                      return num1.compareTo(num2);
                    });
                  }
                  widget.jobData!.sortType = !widget.jobData!.sortType;

                  setState(() {
                    widget.jobData!.sortLevel = false;
                    showList = widget.jobData!.studentDetails;
                  });
                },
                child: Row(
                  children: [
                    if(!widget.jobData!.sortType)
                      Image.asset(
                        'assets/images/no_check_icon.png',
                        width: 16.r,
                        height: 16.r,
                      ),
                    if(widget.jobData!.sortType)
                      Image.asset(
                        'assets/images/check_icon.png',
                        width: 16.r,
                        height: 16.r,
                      ),
                    SizedBox(width: 5.r,),
                    Text(
                      widget.jobData!.sortType?'已提交排序':'未提交排序',
                      style: TextStyle(
                          fontSize: 12.sp,
                          color: Color(0xFF707070)),
                    ),
                  ],
                ),
              ),

              SizedBox(
                width: 20.r,
              ),

              InkWell(
                onTap: (){
                  if (widget.jobData == null) return;
                  if (!widget.jobData!.sortLevel) {
                    showList = followList;
                    setState(() {

                    });
                  } else {
                    widget.jobData!.studentDetails.sort((a, b) {
                      int num1 =
                          a.kgValidRate + a.zgValidRate;
                      int num2 =
                          b.kgValidRate + b.zgValidRate;
                      return num1.compareTo(num2);
                    });
                    showList = widget.jobData!.studentDetails;
                    setState(() {

                    });
                  }
                  widget.jobData!.sortLevel =
                  !widget.jobData!.sortLevel;
                  setState(() {
                    widget.jobData!.sortType = false;
                  });
                },
                child: Row(
                  children: [
                    if(!widget.jobData!.sortLevel)
                      Image.asset(
                        'assets/images/no_check_icon.png',
                        width: 16.r,
                        height: 16.r,
                      ),
                    if(widget.jobData!.sortLevel)
                      Image.asset(
                        'assets/images/check_icon.png',
                        width: 16.r,
                        height: 16.r,
                      ),
                    SizedBox(width: 5.r,),
                    Text(
                      '看关注学生',
                      style: TextStyle(
                          fontSize: 12.sp,
                          color: Color(0xFF707070)),
                    ),
                  ],
                ),
              ),

            ],
          ),
          SizedBox(
            height: 10.r,
          ),
          Row(
            children: [
              Text(
                '注：',
                style: TextStyle(
                    fontSize: 8.sp, color: Color(0xFF717171)),
              ),
              Container(
                width:10.r,
                height: 10.r,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(5.r)),
                  color: Color(0xFF4CC793),
                ),
              ),
              SizedBox(width: 2.r,),
              Text(
                '正确',
                style: TextStyle(
                    fontSize: 8.sp, color: Color(0xFF717171)),
              ),
              SizedBox(width: 15.r,),
              Container(
                width:10.r,
                height: 10.r,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(5.r)),
                  color: Color(0xFFFF7474),
                ),
              ),
              SizedBox(width: 2.r,),
              Text(
                '错误',
                style: TextStyle(
                    fontSize: 8.sp, color: Color(0xFF717171)),
              ),
              SizedBox(width: 15.r,),
              Container(
                width:10.r,
                height: 10.r,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(5.r)),
                  color: Colors.white,
                  // border: Border.all(width: 1.r,color: Colors.grey),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.grey,
                      offset: Offset(1.w, 1.h), //阴影y轴偏移量
                      blurRadius: 4, //阴影模糊程度
                      spreadRadius: 0.1, //阴影扩散程度
                    )
                  ],
                ),
              ),
              SizedBox(width: 2.r,),
              Text(
                '已作答未批阅',
                style: TextStyle(
                    fontSize: 8.sp, color: Color(0xFF717171)),
              ),
              SizedBox(width: 15.r,),
              Container(
                width:10.r,
                height: 10.r,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(5.r)),
                  color: Color(0xFFD3D3D3),
                ),
              ),
              SizedBox(width: 2.r,),
              Text(
                '未做',
                style: TextStyle(
                    fontSize: 8.sp, color: Color(0xFF717171)),
              ),
            ],
          ),
          SizedBox(
            height: 5.r,
          ),
          SizedBox(
            height: showList.length > 5
                ? 350.r
                : showList.length * 50.r +
                40.r,
            child: QuickStudentDataTable(
              headList: [
                '学生姓名',
                '客观题',
                '主观题',
                '客观题状态',
                '主观题状态',
                '未批阅'
              ],
              bodyList: showList,
              jobId: widget.jobId,
              fixedRows: 1,
              fixedCols: 0,
              // hasUnrated: widget.jobData!.hasUnrated,
              hasUnrated: false,
              kgCount: widget.jobData!.kgQuestionCount,
              zgCount: widget.jobData!.zgQuestionCount,
            ),
          )
        ],
      ),
    );
  }
}
