import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:marking_app/common/mixin/common.dart';
import 'package:marking_app/common/model/common/base_structure_result.dart';
import 'package:marking_app/common/model/job/job_data_report.dart';
import 'package:marking_app/components/ReturnToHomepage.dart';
import 'package:marking_app/pages/homework_correction/widget/student_kg_table.dart';
import 'package:marking_app/pages/homework_correction/widget/student_zg_table.dart';
import 'package:marking_app/routes/RouterManager.dart';
import 'package:marking_app/utils/common_utils.dart';
import 'package:marking_app/utils/request/rest_client.dart';
import 'package:marking_app/utils/toast_utils.dart';

class QuickCheckPersonal extends StatefulWidget {
  final int jobId;
  final int studentId;

  const QuickCheckPersonal(
      {Key? key, required this.jobId, required this.studentId})
      : super(key: key);

  @override
  State<QuickCheckPersonal> createState() => _QuickCheckPersonalState();
}

class _QuickCheckPersonalState extends State<QuickCheckPersonal>
    with CommonMixin {
  StudentDetails? studentInfo;

  void initState() {
    super.initState();
    EasyLoading.show(status: 'loading...');
    getJobPersonal();
  }

  void getJobPersonal() async {
    RestClient _client = await getClient();
    Map<String, dynamic> params = {};
    params['jobid'] = widget.jobId;
    // params['jobid'] = '521646983660101';
    params['studentId'] = widget.studentId;
    BaseStructureResult<StudentDetails?> data =
        await _client.getJobPersonalReport(params);
    if(data.data!.studentId != null){
      setState(() {
        studentInfo = data.data;
      });
    }else{
      Navigator.pop(context);
      ToastUtils.showError('暂无数据');
    }
    EasyLoading.dismiss();

  }

  @override
  Widget build(BuildContext context) {
    if (studentInfo == null) {
      return Container();
    }
    return Scaffold(
      backgroundColor: Color.fromRGBO(245, 245, 245, 1),
      appBar: AppBar(
        backgroundColor: Colors.white,
        title: Text(
          studentInfo!.studentName!,
          style: TextStyle(fontSize: 14.sp, color: Color(0xFF000000)),
        ),
        centerTitle: true,
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
        actions: [
          ReturnToHomepage(),
         /* Title(
            color: Color(0xFF6888FD),
            child: Container(
              child: InkWell(
                onTap: (){
                  RouterManager.router.navigateTo(context, '${RouterManager.jobPersonalDetailPath}?studentId=${widget.studentId}&studentName=${Uri.encodeComponent(studentInfo!.studentName!)}');
                },
                child: Padding(
                  padding: EdgeInsets.only(right: 16.r),
                  child: Text('历史作业',style: TextStyle(fontSize: 12.sp,color: Color(0xFF6888FD)),),
                ),
              ),
              alignment: Alignment.center,
            ),
          ),*/

        ],
      ),

      body: SingleChildScrollView(
        child: Column(
          children: [
            Padding(
              padding: EdgeInsets.only(top: 14.r,left: 14.r),
              child: Row(
                children: [
                  InkWell(
                    onTap: (){
                      RouterManager.router.navigateTo(context, '${RouterManager.jobPersonalDetailPath}?studentId=${widget.studentId}&studentName=${Uri.encodeComponent(studentInfo!.studentName!)}');
                    },
                    child: Container(
                      width: 93.r,
                      height: 28.r,
                      decoration: BoxDecoration(
                        color: Color(0xFFEAF3FF),
                        borderRadius: BorderRadius.circular(4.r),
                      ),
                      child: Center(
                        child: Text('历史查询',style: TextStyle(fontSize: 10.r,color: Color(0xFF2080F7)),),
                      ),
                    ),
                  ),
                  SizedBox(width: 10.r,),
                  Container(
                    width: 93.r,
                    height: 28.r,
                    decoration: BoxDecoration(
                      color: Color(0xFFEDFFF7),
                      borderRadius: BorderRadius.circular(4.r),
                    ),
                    child: Center(
                      child: Text('原稿笔迹',style: TextStyle(fontSize: 10.r,color: Color(0xFF4CC793)),),
                    ),
                  ),
                ],
              ),
            ),
            //客观题
            Container(
              padding: EdgeInsets.symmetric(vertical: 14.r, horizontal: 10.r),
              margin: EdgeInsets.symmetric(vertical: 14.r, horizontal: 14.r),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(6.r)),
              ),
              child: Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Text(
                        '客观题',
                        style: TextStyle(
                            fontSize: 14.sp, color: Color(0xFF5C5C5C),fontWeight: FontWeight.w600),
                      ),
                      SizedBox(
                        width: 10.r,
                      ),
                      Text(
                        '${studentInfo!.kgValidRate}%',
                        style: TextStyle(
                            fontSize: 14.sp, color: Color(0xFF6888FD),fontWeight: FontWeight.w600),
                      ),
                    ],
                  ),
                  SizedBox(height: 10.r,),
                  SizedBox(
                    height: studentInfo!.kgDetails.length>8?300.r:studentInfo!.kgDetails.length * 40.r + 40.r,
                    child: StudentKgTable(
                      headList: ['题号', '学生答案', '标准答案'],
                      bodyList: studentInfo!.kgDetails,
                    ),
                  )
                ],
              ),
            ),
            SizedBox(height: 15.r,),
            //主观题
            Container(
              padding: EdgeInsets.symmetric(vertical: 14.r, horizontal: 10.r),
              margin: EdgeInsets.symmetric(vertical: 14.r, horizontal: 14.r),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(6.r)),
              ),
              child: Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Text(
                        '主观题',
                        style: TextStyle(
                            fontSize: 14.sp, color: Color(0xFF5C5C5C),fontWeight: FontWeight.w600),
                      ),
                      SizedBox(
                        width: 10.r,
                      ),
                      Text(
                        '${studentInfo!.zgValidRate}%',
                        style: TextStyle(
                            fontSize: 14.sp, color: Color(0xFF6888FD),fontWeight: FontWeight.w600),
                      ),
                    ],
                  ),
                  SizedBox(height: 10.r,),
                  SizedBox(
                    height: studentInfo!.zgDetails.length>8?300.r:studentInfo!.zgDetails.length * 40.r + 40.r,
                    child: StudentZgTable(
                      headList: ['题号', '用时', '学生答案','批注结果','批注'],
                      bodyList: studentInfo!.zgDetails,
                    ),
                  )
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
