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/annotate_list_to_refresh.dart';
import 'package:making_school_asignment_app/page/global_widget/ReturnToHomepage.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/children/homework_review/components/bottom_operation_bar.dart';
import 'package:making_school_asignment_app/page/home_page/children/homework_review/components/question_paper_view.dart';
import 'package:making_school_asignment_app/page/home_page/home_logic.dart';

import 'components/dropdown_switch_students_type.dart';
import 'components/favorite_widget.dart';
import 'configuration_files/index.dart';

class HomeworkReview extends StatelessWidget {
  const HomeworkReview({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HomeworkReviewLogic>(builder: (logic) {
      final sateData = logic.state;
      return PopScope(
        canPop: false,
        onPopInvoked: (e) {
          if (e && sateData.needRefresh) {
            Get.find<AnnotateClassLogic>().getList();
            Get.find<HomeLogic>().getList();
            logic.eventFire(model: AnnotateListToRefresh());
          }
        },
        child: Scaffold(
          backgroundColor: Colors.transparent,
          body: Stack(
            children: [
              // body内容，顶部留出自定义AppBar高度
              const Padding(
                padding: EdgeInsets.only(top: kToolbarHeight),
                child: Column(
                  children: [
                    // 下拉切换
                    DropdownSwitchStudentsType(),
                    // 试题展示区和打分区
                    Expanded(child: QuestionPaperView()),
                    // 底部功能区
                    BottomAnnotationSwitch()
                  ],
                ),
              ),
              // 顶部自定义AppBar
              Container(
                height: kToolbarHeight,
                color: Colors.white,
                child: Row(
                  children: [
                    SizedBox(width: 5.w),
                    IconButton(
                        icon: const Icon(Icons.arrow_back_ios, color: Colors.black),
                        onPressed: () => Get.back(),
                        tooltip: '返回'),
                    Expanded(
                      child: Text(
                        sateData.param.value.homeworkName,
                        style: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.w600),
                        overflow: TextOverflow.ellipsis,
                      ),
                    ),
                    const FavoriteWidget(),
                    SizedBox(width: 10.w),
                    const ReturnToHomepage(),
                    SizedBox(width: 8.w),
                  ],
                ),
              ),
            ],
          ),
        ),
      );
    });
  }
}
