import 'package:flutter/material.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/page/global_widget/MyEmptyWidget.dart';
import 'package:making_school_asignment_app/page/global_widget/ReturnToHomepage.dart';
import 'package:making_school_asignment_app/page/global_widget/my_text.dart';
import 'package:making_school_asignment_app/page/home_page/children/job_report/widget/dropdown_selection.dart';
import 'package:making_school_asignment_app/page/home_page/children/job_report/widget/knowledge_point.dart';
import 'package:making_school_asignment_app/page/home_page/children/job_report/widget/personnel_data_overview.dart';
import 'package:making_school_asignment_app/page/home_page/children/job_report/widget/top_count.dart';
import 'package:making_school_asignment_app/page/home_page/children/quick_data_check/widget/kgt_zgt_table.dart';

import 'job_report_logic.dart';

class JobReportPage extends StatefulWidget {
  const JobReportPage({super.key});

  @override
  State<JobReportPage> createState() => _JobReportPageState();
}

class _JobReportPageState extends State<JobReportPage> {
  final logic = Get.find<JobReportLogic>();
  final state = Get.find<JobReportLogic>().state;

  @override
  Widget build(BuildContext context) {
    return OrientationBuilder(builder: (BuildContext context, Orientation orientation) {
      return Scaffold(
        backgroundColor: const Color.fromRGBO(245, 245, 245, 1),
        appBar: AppBar(
          backgroundColor: Colors.white,
          centerTitle: true,
          title: Center(child: Obx(() {
            return quickText(
              '${state.title.value}作业报告',
              size: 14.sp,
              color: const Color.fromRGBO(51, 51, 51, 1),
            );
          })),
          leading: IconButton(
            icon: const Icon(Icons.arrow_back_ios, color: Colors.black),
            onPressed: () => Get.back(),
          ),
          actions: const [
            ReturnToHomepage(),
          ],
        ),
        body: Obx(() {
          if (state.hasData.value) {
            return SingleChildScrollView(
              child: Column(
                children: [
                  // 下拉框
                  Container(
                    padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 10.w),
                    decoration: const BoxDecoration(
                      color: Colors.white,
                    ),
                    child: Row(
                      children: [
                        Obx(() {
                          return DropdownSelection(
                              involveClasses: state.involveClasses.value,
                              classData: state.classData.value,
                              onClassSelected: (AnnotatedClass item) {
                                state.classData.value = item;
                                if (item.grade == -1) state.classData.value = state.defaultClass;
                                logic.getWorkData();
                              });
                        }),
                        // Expanded(child: Text('')),
                      ],
                    ),
                  ),
                  //完成率、正确率
                  TopCount(
                      state.dataCount, state.classData.value.className ?? '', state.homeworkId.value, state.subject),
                  //客观题、主观题
                  KgtZgtTable(
                    studentCount: state.dataCount.studentCount!,
                    homeworkId: state.homeworkId.value,
                    kgReport: state.kgReport,
                    zgReport: state.zgReport,
                    kgtOkRate: state.dataCount.kgtOkRate!.toStringAsFixed(0),
                    zgtOkRate: state.dataCount.zgtOkRate!.toStringAsFixed(0),
                    kgtCorrectRate: state.dataCount.kgtCorrectRate!.toStringAsFixed(0),
                    zgtCorrectRate: state.dataCount.zgtCorrectRate!.toStringAsFixed(0),
                    subject: state.subject,
                  ),
                  // 掌握知识点的情况
                  Container(
                      margin: EdgeInsets.symmetric(horizontal: 10.r),
                      child: KnowledgePoint(
                        knowsList: state.knowsList,
                        data: state.homeData,
                        className: state.classData.value.className ?? '',
                        homeworkId: state.homeworkId.value,
                        subject: state.subject,
                      )),
                  // 掌握知识点的情况
                  /* Container(
                  margin: EdgeInsets.symmetric(horizontal: 10.r),
                  child: $OverallPerformance(data.studentCount, data.overallTitles)),
              // 单位时间答题情况
              Container(
                  margin: EdgeInsets.symmetric(horizontal: 10.r),
                  child: $UnitTimeAnsweringSituation(widget.id, data.questionAnswerInfos)),*/
                  // 人员数据概况
                  Container(
                      margin: EdgeInsets.symmetric(horizontal: 10.r),
                      child: PersonnelDataOverview(studentList: state.studentList.value)),

                  SizedBox(
                    height: 30.r,
                  ),
                ],
              ),
            );
          } else {
            return Padding(
                padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 2 - 200.r),
                child: const MyEmptyWidget());
          }
        }),
      );
    });
  }

  @override
  void dispose() {
    Get.delete<JobReportLogic>();
    super.dispose();
  }
}
