import 'package:cpt_uk/modules/report/attendance_report/attendance_report_page.dart';
import 'package:cpt_uk/modules/report/labour_report/labour_report_page.dart';
import 'package:cpt_uk/modules/report/outlet_staff_report/outlet_staff_report_page.dart';
import 'package:cpt_uk/modules/report/working_hours_report/working_hours_report_page.dart';
import 'package:domain/entity/home_module.dart';
import 'package:domain/entity/response/hotel_info_entity.dart';
import 'package:get/get.dart';
import 'package:plugin_basic/service/app_config_service.dart';
import 'package:plugin_basic/service/user_service.dart';
import 'package:plugin_platform/engine/toast/toast_engine.dart';
import 'package:router/componentRouter/component_router_service.dart';
import 'package:shared/utils/log_utils.dart';

import '../casual_payout_report/casual_payout_report_page.dart';
import '../casual_report/casual_report_page.dart';
import '../finance_report/report_finance_page.dart';
import 'report_list_state.dart';

class ReportListController extends GetxController {
  final ReportListState state = ReportListState();

  /// 获取报表的数据
  void setupReportData() async {
    final hotelInfo = UserService.to.getHotelInfo;

    // List<HotelInfoMenusChildren>? list = hotelInfo.menus?.firstWhereOrNull((element) => element.key == "report")?.children;
    //
    // Log.d("list:$list");
    //
    // if (list != null && list.isNotEmpty) {
    //   //有数据，判断是刷新还是加载更多的数据
    //   state.datas.clear();
    //
    //   //如果是管理员登录，根据Key筛选需要展示的模块
    //   for (var children in list) {
    //     if (children.key != null) {
    //       state.datas.addAll(_filterModulesByKey(children.key!));
    //     }
    //   }
    // } else {
    //   //清除
    //   state.datas.clear();
    // }

    state.datas.clear();
    state.datas.addAll(state.modules);

    update();
  }

  List<HomeModule> _filterModulesByKey(String key) {
    return state.modules.where((module) => module.key == key).toList();
  }

  @override
  void onReady() async {
    super.onReady();
    setupReportData();
  }

  /// 跳转到指定的模块中去
  void gotoReportPage(HomeModule module) {
    switch (module.key) {
      case 'labour':
        UKLabourReportPage.startInstance();
        break;
      case 'outlet':
        UKOutletStaffReportPage.startInstance();
        break;
      case 'finale':
        UKReportFinancePage.startInstance();
        break;
      case 'hours':
        UKWorkingHoursReportPage.startInstance();
        break;
      case 'attendance':
        UKAttendanceReportPage.startInstance();
        break;
      case 'payout':
        UKCasualPayoutReportPage.startInstance();
        break;
      case 'casual':
        UKCasualReportPage.startInstance();
        break;
    }
  }
}
