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/knowledge_points_grasp.dart';
import 'package:making_school_asignment_app/common/mixins/request_tool_mixin.dart';
import 'package:making_school_asignment_app/common/utils/toast_utils.dart';

import 'knowledge_points_grasp_state.dart';

class KnowledgePointsGraspLogic extends GetxController with RequestToolMixin, GetSingleTickerProviderStateMixin {
  final KnowledgePointsGraspState state = KnowledgePointsGraspState();
  //文本输入框控制器
  late final TextEditingController textController;
  late final EasyRefreshController refreshController;
  late TabController tabController;

  @override
  void onInit() {
    super.onInit();
    final subject = Get.arguments['subject'];
    state.subject = subject == 0 ? null : subject;

    state.classId = Get.arguments['classId'] ?? '';
    textController = TextEditingController();
    refreshController = EasyRefreshController();
    tabController = TabController(length: 3, vsync: this);
    EasyLoading.show(status: 'loading...');
    getList();
  }

  void getList() async {
    try {
      ToastUtils.showLoading();
      List<KnowledgePointsGrasp> data = await getClient()
          .getKnowledgeReport(state.dateStart, state.dateEnd, textController.text, state.classId, state.subject);
      print('data: ${data.length}');
      state.dataList.value = data;
    } catch (_) {
    } finally {
      ToastUtils.dismiss();
    }
  }

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