import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:making_school_asignment_app/page/global_widget/my_text.dart';
import 'package:making_school_asignment_app/page/home_page/children/read_over/widget/annotate_list.dart';
import 'package:making_school_asignment_app/routes/app_pages.dart';

import 'read_over_logic.dart';

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

  @override
  State<ReadOverPage> createState() => _ReadOverPageState();
}

class _ReadOverPageState extends State<ReadOverPage> {
  final logic = Get.find<ReadOverLogic>();
  final state = Get.find<ReadOverLogic>().state;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion(
      value: const SystemUiOverlayStyle(
        /*   systemNavigationBarColor: Color(0xFF000000),
        systemNavigationBarDividerColor: null,*/
        statusBarColor: Colors.white,
        systemNavigationBarDividerColor: null,
        systemNavigationBarIconBrightness: Brightness.light,
        statusBarIconBrightness: Brightness.light,
        statusBarBrightness: Brightness.light,
      ),
      child: Scaffold(
        backgroundColor: Colors.white,
        body: OrientationBuilder(
          builder: (BuildContext context, Orientation orientation) {
            return Column(
              children: <Widget>[
                Container(
                  color: Colors.white,
                  margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
                  padding: EdgeInsets.only(bottom: 9.h, top: 4.h),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Expanded(
                          flex: 1,
                          child: InkWell(
                            onTap: () {
                              Get.back();
                            },
                            child: Container(
                              height: 30.h,
                              alignment: Alignment.centerLeft,
                              padding: EdgeInsets.only(left: 10.w),
                              child: Icon(
                                Icons.arrow_back_ios_sharp,
                                size: 16.sp,
                              ),
                            ),
                          )),
                      Expanded(
                        flex: 4,
                        child: Container(
                          padding: EdgeInsets.symmetric(vertical: 2.h),
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            color: const Color.fromRGBO(243, 243, 243, 1),
                            borderRadius: BorderRadius.circular(8.r),
                          ),
                          child: TabBar(
                            padding: EdgeInsets.zero,
                            indicatorPadding: EdgeInsets.zero,
                            indicatorWeight: 0,
                            labelPadding: EdgeInsets.symmetric(horizontal: 2.w),
                            controller: logic.tabController,
                            unselectedLabelStyle: TextStyle(
                              fontSize: 14.sp,
                              color: const Color.fromRGBO(69, 83, 100, 1),
                            ),
                            labelStyle: TextStyle(
                              fontSize: 14.sp,
                              color: const Color(0xFF8C68FF),
                            ),
                            // labelColor: const Color.fromRGBO(45, 56, 76, 1),
                            indicator: const UnderlineTabIndicator(
                              borderSide: BorderSide(
                                  width: 0, // 设置边界宽度为0，从而去除下划线
                                  color: Colors.transparent),
                            ),
                            onTap: (index) {
                              state.tabIndex.value = index;
                              if (index == 1 && state.completedToRefresh) {
                                // 已阅卷
                                // _refreshController2.callRefresh();
                                state.completedToRefresh = false;
                              }
                            },
                            tabs: <Widget>[
                              Tab(
                                iconMargin: EdgeInsets.zero,
                                height: 34.h,
                                child: Obx(() {
                                  return Container(
                                    width: 140.w,
                                    alignment: Alignment.center,
                                    decoration: BoxDecoration(
                                      color: state.tabIndex.value == 0 ? const Color.fromRGBO(255, 255, 255, 1) : null,
                                      borderRadius: BorderRadius.all(Radius.circular(8.r)),
                                    ),
                                    child: quickText(
                                      '待批阅',
                                      size: 14.sp,
                                      color: state.tabIndex.value == 0
                                          ? Theme.of(context).primaryColor
                                          : const Color.fromRGBO(80, 94, 110, 1),
                                      fontWeight: state.tabIndex.value == 0 ? FontWeight.bold : null,
                                    ),
                                  );
                                }),
                              ),
                              Tab(
                                iconMargin: EdgeInsets.zero,
                                height: 34.h,
                                child: Obx(() {
                                  return Container(
                                    width: 140.w,
                                    alignment: Alignment.center,
                                    decoration: BoxDecoration(
                                      color: state.tabIndex.value == 1 ? const Color.fromRGBO(255, 255, 255, 1) : null,
                                      borderRadius: BorderRadius.all(Radius.circular(8.r)),
                                    ),
                                    child: quickText(
                                      '已批阅',
                                      size: 14.sp,
                                      color: state.tabIndex.value == 1
                                          ? Theme.of(context).primaryColor
                                          : const Color.fromRGBO(80, 94, 110, 1),
                                      fontWeight: state.tabIndex.value == 1 ? FontWeight.bold : null,
                                    ),
                                  );
                                }),
                              ),
                            ],
                          ),
                        ),
                      ),
                      Expanded(
                        flex: 1,
                        child: InkWell(
                          onTap: () {
                            Get.toNamed(Routes.studentHistoryWorkPage, arguments: {'page': 'set'});
                          },
                          child: Icon(const IconData(0xe63e, fontFamily: "AlibabaIcon"),
                              color: const Color.fromRGBO(44, 48, 63, 1), size: 24.sp),
                        ),
                      ),
                    ],
                  ),
                ),
                Expanded(
                  child: Container(
                    color: const Color.fromRGBO(245, 245, 245, 1),
                    child: Obx(() {
                      return AnnotateList(
                        tabIndex: state.tabIndex.value,
                        assessType: 0,
                      );
                    }),
                  ),
                ),
              ],
            );
          },
        ),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<ReadOverLogic>();
    logic.homeController.getList();
    SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
      statusBarColor: Colors.transparent, //状态栏背景颜色
      statusBarIconBrightness: Brightness.light,
      systemStatusBarContrastEnforced: false,
    ));
    super.dispose();
  }
}
