import 'package:fis_jsonrpc/rpc.dart';
import 'package:get/get.dart';
import 'package:vitalapp/architecture/utils/prompt_box.dart';
import 'package:vitalapp/managers/interfaces/follow_up.dart';
import 'package:vitalapp/pages/check/follow_up/state.dart';
import 'package:vitalapp/pages/check/models/form.dart';
import 'package:vitalapp/store/store.dart';

class FollowUpController extends GetxController {
  FollowUpController();
  final state = FollowUpState();

  final _followUpManager = Get.find<IFollowUpManager>();

  late String patientCode = "";
  late String patientName = "";

  _initData() {
    update(["follow_up"]);
    // final p = Get.parameters;
    patientCode = Store.user.currentSelectPatientInfo?.code ?? '';
    patientName = Store.user.currentSelectPatientInfo?.patientName ?? '';
  }

  void onTap() {}
  List<MenuItem> menuList = [
    // MenuItem(label: "肺结核随访服务", value: 'FJHSFFW'),
    // MenuItem(label: "肺结核入户随访", value: 'FJHRHSF'),
    // MenuItem(label: "冠心病", value: 'GXB'),
    // MenuItem(label: "脑卒中", value: 'NCZ'),
    // MenuItem(label: "严重精神障碍随访服务", value: 'YZJSZASFFW'),
    // MenuItem(label: "严重精神障碍个人信息补充", value: 'YZJSZAGRXXBC'),
    MenuItem(label: "2 型糖尿病", value: 'TNB'),
    MenuItem(label: "高血压", value: 'GXY'),
    MenuItem(label: "老年人中医药健康管理服务记录表", value: 'LNRZYYJKGLFWJL'),
    // MenuItem(label: "老年人生活自理能力评估表", value: 'LNRSHZLNLPGB'),
    // MenuItem(label: "产后42天健康检查列表", value: 'YCF_CH42TJKJCLB'),
    // MenuItem(label: "产后访视列表", value: 'YCF_CHFSLB'),
    // MenuItem(label: "2~5次产前随访列表", value: 'YCF_2_5CCQSFLB'),
    // MenuItem(label: "第一次产前检查列表", value: 'YCF_DYCCQJCLB'),
    // MenuItem(label: "基本信息", value: 'YCF_JBXX'),
    // MenuItem(label: "儿童中医药健康管理列表", value: 'ET_ZYYJKGLLB'),
    // MenuItem(label: "3~6岁儿童健康检查列表", value: 'ET_3_6SETJKJCLB'),
    // MenuItem(label: "1~2岁儿童健康检查列表", value: 'ET_1_2SETJKJCLB'),
    // MenuItem(label: "1岁内儿童健康检查列表", value: 'ET_1SNETJKJCLB'),
    // MenuItem(label: "新生儿访视列表", value: 'ET_XSEFSLB'),
  ];
  // @override
  // void onInit() {
  //   super.onInit();
  // }
  Future<void> createFollowUp(key, templateCode, data) async {
    List<String> followUpPhotos = [];
    if (state.followUpPhoto?.isNotEmpty ?? false) {
      followUpPhotos = [state.followUpPhoto!];
    }
    final result = await _followUpManager.createFollowUp(
      CreateFollowUpRequest(
        key: key,
        patientCode: patientCode,
        templateCode: templateCode,
        followUpData: data,
        followUpTime: state.followUpTime,
        nextFollowUpTime: state.nextFollowUpTime,
        followUpMode: state.followUpMode ?? FollowUpModeEnum.Outpatient,
        followUpPhotos: followUpPhotos,
      ),
    );
    if (result.isNotEmpty) {
      PromptBox.toast('保存成功');
    }
  }

  @override
  void onReady() {
    super.onReady();
    _initData();
  }

  // @override
  // void onClose() {
  //   super.onClose();
  // }
}
