import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:making_school_asignment_app/common/job/class_item.dart';
import 'package:making_school_asignment_app/common/job/work_student.dart';
import 'package:making_school_asignment_app/common/job/work_student_params.dart';
import 'package:making_school_asignment_app/common/mixins/request_tool_mixin.dart';
import 'package:making_school_asignment_app/routes/app_pages.dart';

import 'answer_trajectory_state.dart';

class AnswerTrajectoryLogic extends GetxController with RequestToolMixin, GetTickerProviderStateMixin{
  final AnswerTrajectoryState state = AnswerTrajectoryState();
  late TabController tabController;
  late final EasyRefreshController refreshController;
  late final EasyRefreshController refreshController2;
  @override
  void onInit(){
    super.onInit();
    refreshController = EasyRefreshController();
    refreshController2 = EasyRefreshController();
    tabController =
        TabController(initialIndex: state.tabIndex.value, length: 2, vsync: this);
    getStudentGroups();
    getWorkList();
  }

   goNextPage(id, title,subject) {
     Get.toNamed(Routes.classStudentPage,arguments: {'title':title,'classId':id,'page':'answerTrajectory','subject':subject});
   }

  void getStudentGroups() async{
    List<ClassItem> data = await getClient().getStudentClass();
    state.studentGroups.value = data;
    EasyLoading.dismiss();
    refreshController.finishRefresh();
  }

  void getWorkList() async{
    WorkStudentParams params = WorkStudentParams(
      assessType: 0,
      pageSize: 10,
    );
    params.pageNumber = state.page;
    WorkStudent data = await getClient().getAnnotatedList(params);
    state.jobList.value = data.items;
    EasyLoading.dismiss();
    refreshController2.finishRefresh();
  }

  @override
  void dispose(){
    super.dispose();
    tabController.dispose();
    refreshController.dispose();
    refreshController2.dispose();
  }
}
