import 'package:fis_jsonrpc/services/exam.m.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vnoteapp/architecture/defines.dart';
import 'package:vnoteapp/managers/interfaces/health_check_record.dart';
import 'package:vnoteapp/pages/check/healthCheckRecord/state.dart';
import 'package:vnoteapp/pages/check/widgets/configurable_card.dart';

class HealthCheckRecordController extends FControllerBase {
  HealthCheckRecordController();
  final state = HealthCheckRecordState();
  final _healthCheckRecordManager = Get.find<IHealthCehckRecordManager>();
  late String patientCode;
  @override
  void onReady() {
    super.onReady();
    _initData();
  }

  _initData() {
    update(["contract_records"]);
    final p = Get.parameters;
    patientCode = p['patientCode'] ?? "";
    _getExamRecordList();
  }

  Future<void> _getExamRecordList() async {
    try {
      var result =
          await _healthCheckRecordManager.getExamRecordList(patientCode);
      if (result != null) {
        state.examRecordDTOList = result;
      }
    } catch (e) {
      return;
    }
  }

  toCheckPage(ExamRecordDataDTO dataDTO) {
    Get.to(
      ConfigurableCard(
        cardKey: dataDTO.key!,
        examData: dataDTO.examData,
        callBack: (key, templateCode, data) async {
          // await controller.createExam(key, templateCode, data);
          // Get.back();
        },
      ),
      transition: Transition.rightToLeft,
    );
  }

  String getHealthCheckRecordType(String key) {
    switch (key) {
      case 'ZZYBZK':
        return '症状、一般状况';
      case 'SHFS':
        return '生活方式';
      case 'ZQCT':
        return '脏器、查体';
      case 'FZJC':
        return '辅助检查';
      case 'XCZYWT':
        return '现存主要问题';
      case 'ZYYYFMYGHYFJZS':
        return '住院、用药、非免疫规划预防接种史';
      case 'JKPJJZD':
        return '健康评价及指导';
      default:
        return "";
    }
  }

  String examStateTransition(ExamStateEnum state) {
    switch (state) {
      case ExamStateEnum.Unchecked:
        return "未体检";
      case ExamStateEnum.Invalid:
        return "已作废";
      case ExamStateEnum.Inspected:
        return "已体检";
      default:
        return "";
    }
  }

  MaterialColor examStateColors(ExamStateEnum state) {
    switch (state) {
      case ExamStateEnum.Unchecked:
        return Colors.grey;
      case ExamStateEnum.Invalid:
        return Colors.red;
      case ExamStateEnum.Inspected:
        return Colors.green;
      default:
        return Colors.blue;
    }
  }
}
