import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:making_school_asignment_app/common/job/annotated_class.dart';
import 'package:making_school_asignment_app/common/utils/utils.dart';
import 'package:making_school_asignment_app/page/global_widget/my_text.dart';
import 'package:making_school_asignment_app/page/global_widget/show_student_list.dart';
import 'package:making_school_asignment_app/page/home_page/children/annotate_class/annotate_class_logic.dart';
import 'package:making_school_asignment_app/page/home_page/widget/progress_bar.dart';
import 'package:making_school_asignment_app/routes/app_pages.dart';

class CompletedAnnotateItem extends StatelessWidget {
  final AnnotatedClass taskItem;
  final AnnotateClassLogic logic;
  final String name;
  const CompletedAnnotateItem({Key? key, required this.taskItem, required this.logic,required this.name}) : super(key: key);

  void showStudentList(context, List<AnnotatedStudents> students, [bool submitted = false]) async {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return ShowStudentList(
          title: '${taskItem.className ?? ''} ${submitted ? '已提交' : '未提交'}作业学生',
          studentList: students,
          homeworkId: logic.state.homeworkId.value,
            subject:logic.state.subject,
        );
      },
    );
    EasyLoading.dismiss();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(6.r)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Container(
            padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 6.h),
            alignment: Alignment.centerLeft,
            decoration: BoxDecoration(
              border: Border(bottom: BorderSide(color: Color.fromRGBO(238, 238, 238, 1), width: 0.5.r)),
            ),
            child: quickText(taskItem.className, color: Theme.of(context).primaryColor, size: 12.sp),
          ),
          Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              ProgressBar(
                color: const Color(0xFFADDCA5),
                percent: taskItem.kgtCorrectRate / 100,
                title: '客观题正确率：',
                padingEdg: EdgeInsets.only(left: 10.w, right: 10.w),
                fontSize: 8.sp,
                lineHeight: 5.h,
                marginEdg: EdgeInsets.only(top: 5.h),
              ),
              ProgressBar(
                color: const Color(0xFFADDCA5),
                percent: taskItem.zgtCorrectRate / 100,
                title: '主观题正确率：',
                fontSize: 8.sp,
                lineHeight: 5.h,
                padingEdg: EdgeInsets.only(left: 10.w, right: 10.w),
                marginEdg: EdgeInsets.only(top: 5.h),
              ),
              ProgressBar(
                color: const Color(0xFFADDCA5),
                percent: taskItem.correctRate / 100,
                title: '总正确率：',
                fontSize: 8.sp,
                lineHeight: 5.h,
                padingEdg: EdgeInsets.only(left: 10.w, right: 10.w),
                marginEdg: EdgeInsets.only(top: 5.h),
              ),
            ],
          ),
          SizedBox(height: Utils.isPad() ? 4.h : 10.h),
          Padding(
            padding: EdgeInsets.only(left: 10.w, right: 10.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Expanded(
                  flex: 4,
                  child: Material(
                    color: Theme.of(context).primaryColor,
                    borderRadius: BorderRadius.circular(16.r),
                    child: InkWell(
                      onTap: () {
                        EasyLoading.show(status: 'loading...');
                        showStudentList(context, taskItem.commitStudent!, true);
                      },
                      borderRadius: BorderRadius.circular(8.r),
                      splashColor: Theme.of(context).primaryColor,
                      child: Container(
                        alignment: Alignment.center,
                        padding: EdgeInsets.symmetric(vertical: 4.h),
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular(20.r),
                        ),
                        child: quickText('已提交:${taskItem.commitStudentCount}', size: 8.sp, color: Colors.white),
                      ),
                    ),
                  ),
                ),
                const Expanded(flex: 1, child: SizedBox()),
                Expanded(
                  flex: 4,
                  child: Material(
                    color: Color.fromRGBO(244, 244, 244, 1),
                    borderRadius: BorderRadius.circular(20.r),
                    child: InkWell(
                      onTap: () {
                        EasyLoading.show(status: 'loading...');
                        showStudentList(context, taskItem.noCommitStudent!);
                      },
                      splashColor: Theme.of(context).primaryColor,
                      borderRadius: BorderRadius.circular(8.r),
                      child: Container(
                        alignment: Alignment.center,
                        padding: EdgeInsets.symmetric(vertical: 4.h),
                        decoration: BoxDecoration(borderRadius: BorderRadius.circular(20.r)),
                        child: quickText('未提交:${taskItem.noCommitStudentCount}', size: 8.sp, color: Color.fromRGBO(102, 102, 102, 1)),
                      ),
                    ),
                  ),
                ),
                const Expanded(flex: 1, child: SizedBox()),
                Expanded(
                    flex: 4,
                    child: Material(
                      color: Color.fromRGBO(244, 244, 244, 1),
                      borderRadius: BorderRadius.circular(20.r),
                      child: InkWell(
                        onTap: () {
                          Get.toNamed(Routes.favStudentPage,arguments: {'homeworkName':name,'classId':taskItem.classId,'homeworkId':logic.state.homeworkId.value,'grade':taskItem.grade});
                        },
                        splashColor: Theme.of(context).primaryColor,
                        borderRadius: BorderRadius.circular(8.r),
                        child: Container(
                          alignment: Alignment.center,
                          padding: EdgeInsets.symmetric(vertical: 4.h),
                          decoration: BoxDecoration(borderRadius: BorderRadius.circular(20.r)),
                          child: quickText('收藏夹${taskItem.homeworkFavs.isNotEmpty?'(${taskItem.homeworkFavs.length})':''}', size: 8.sp, color: Color.fromRGBO(102, 102, 102, 1)),
                        ),
                      ),
                    )),
              ],
            ),
          ),
          SizedBox(height: Utils.isPad() ? 4.h : 10.h),
          Container(
            decoration: BoxDecoration(
              borderRadius: BorderRadius.only(
                bottomLeft: Radius.circular(10.r),
                bottomRight: Radius.circular(10.r),
              ),
              color: Colors.white,
              boxShadow: const [
                BoxShadow(
                  color: Color.fromRGBO(0, 0, 0, 0.15),
                  offset: Offset(0, -0.0001), //阴影y轴偏移量
                  blurRadius: 5, //阴影模糊程度
                  spreadRadius: 0, //阴影扩散程度
                )
              ],
            ),
            child: Row(children: [
              Expanded(
                child: InkWell(
                  onTap: () {
                    logic.goQuickDataCheck(taskItem);
                  },
                  child: Container(
                    alignment: Alignment.center,
                    child: quickText('数据快查', color: Color.fromRGBO(118, 118, 118, 1), size: 11.sp),
                  ),
                ),
              ),
              Container(width: 1.w, height: 26.h, color: Color.fromRGBO(221, 221, 221, 1)),
              Expanded(
                  child: InkWell(
                onTap: () {
                  logic.gojobReport(taskItem);
                },
                child: Container(
                  alignment: Alignment.center,
                  child: quickText('查看报告', color: Color.fromRGBO(118, 118, 118, 1), size: 10.sp),
                ),
              )),
            ]),
          ),
        ],
      ),
    );
  }
}
