import 'package:fis_i18n/i18n.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:flyinsono/architecture/states/states.dart';
import 'package:flyinsono/managers/server_config_manager.dart';
import 'package:flyinsono/views/mobile/confirm_application_page/widgets/select_sheet.dart';
import 'package:get/get.dart';

class ConfirmApplicationPageState {
  final Rx<DateTime?> _startDateTime = Rx(null);
  final Rx<DateTime?> _endDateTime = Rx(null);
  final RxString _consultationCode = RxString('');
  final Rx<ConsultationDetailDTO> _consultationDetailDTO =
      Rx(ConsultationDetailDTO());
  final Rx<List<FSelectSheetModel>> _expertList = Rx([]);
  final Rx<List<FSelectSheetModel>> _organizationList = Rx([]);
  final Rx<List<FSelectSheetModel>> _allSelectableParticipants = Rx([]);
  final RxList<String> _selectParticipantsList = RxList([]);

  final Rx<String?> _expertUserCode = Rx(null);
  final Rx<String> _assistantPhysicianName = Rx('');
  final Rx<String> _assistantPhysicianCode = Rx('');
  final Rx<String?> _participantsListString = Rx(null);
  final Rx<String?> _currectOrganization = Rx(Store.user.rootOrganizationCode);
  final Rx<String> _currectReminderTimeString =
      Rx(i18nBook.realTimeConsultation.minBeforeStart15.t);
  final Rx<String> _currectReminderMethodString =
      Rx(i18nBook.realTimeConsultation.inAppReminder.t);
  final Rx<String?> _consultationDescription = Rx(null);
  final Rx<List<String>> _selectParticipantsNameList = Rx([]);

  final Rx<List<ConsultationReminderTimeEnum>>
      _currectSelectedReminderTimeList =
      Rx([ConsultationReminderTimeEnum.FifteenMinutes]);
  final Rx<List<int>> _currectSelectedReminderTimeIndexList = Rx([0]);

  final Rx<List<ConsultationReminderMode>> _currectSelectedReminderMethodList =
      Rx([ConsultationReminderMode.Application]);
  final Rx<List<int>> _currectSelectedReminderMethodIndexList = Rx([0]);

  DateTime? get startDateTime => _startDateTime.value;
  set startDateTime(DateTime? value) => _startDateTime.value = value;

  DateTime? get endDateTime => _endDateTime.value;
  set endDateTime(DateTime? value) => _endDateTime.value = value;

  /// 会诊编号
  String get consultationCode => _consultationCode.value;
  set consultationCode(String v) => _consultationCode.value = v;

  /// 会诊详情
  ConsultationDetailDTO get consultationDetail => _consultationDetailDTO.value;
  set consultationDetail(ConsultationDetailDTO v) =>
      _consultationDetailDTO.value = v;

  /// 会诊专家集合
  List<FSelectSheetModel> get expertList => _expertList.value;
  set expertList(List<FSelectSheetModel> v) => _expertList.value = v;

  /// 参与人的集合
  List<String> get selectParticipantsList => _selectParticipantsList.value;
  set selectParticipantsList(List<String> v) =>
      _selectParticipantsList.value = v;

  /// 参与人名字的集合
  List<String> get selectParticipantsNameList =>
      _selectParticipantsNameList.value;
  set selectParticipantsNameList(List<String> v) =>
      _selectParticipantsNameList.value = v;

  /// 可转诊机构集合
  List<FSelectSheetModel> get organizationList => _organizationList.value;
  set organizationList(List<FSelectSheetModel> v) =>
      _organizationList.value = v;

  /// 机构下面的人集合
  List<FSelectSheetModel> get allSelectableParticipants =>
      _allSelectableParticipants.value;
  set allSelectableParticipants(List<FSelectSheetModel> v) =>
      _allSelectableParticipants.value = v;

  /// 会诊专家的code
  String? get expertUserCode => _expertUserCode.value;
  set expertUserCode(String? v) => _expertUserCode.value = v;

  /// 所有参与人的名字
  String? get participantsListString => _participantsListString.value;
  set participantsListString(String? v) => _participantsListString.value = v;

  /// 当前机构的code
  String? get currectOrganization => _currectOrganization.value;
  set currectOrganization(String? v) => _currectOrganization.value = v;

  /// 助理医师
  String get assistantPhysicianName => _assistantPhysicianName.value;
  set assistantPhysicianName(String v) => _assistantPhysicianName.value = v;

  /// 助理医师的code
  String get assistantPhysicianCode => _assistantPhysicianCode.value;
  set assistantPhysicianCode(String v) => _assistantPhysicianCode.value = v;

  /// 会诊描述
  String? get consultationDescription => _consultationDescription.value;
  set consultationDescription(String? v) => _consultationDescription.value = v;

  /// 当前选中的提醒时间
  List<ConsultationReminderTimeEnum> get currectSelectedReminderTimeList =>
      _currectSelectedReminderTimeList.value;
  set currectSelectedReminderTimeList(List<ConsultationReminderTimeEnum> v) {
    _currectSelectedReminderTimeList.value = v;
    String _reminderTimeString = '开始前';
    for (ConsultationReminderTimeEnum i in v) {
      if (i == ConsultationReminderTimeEnum.FifteenMinutes) {
        _reminderTimeString = _reminderTimeString + '15分钟 ';
      } else if (i == ConsultationReminderTimeEnum.ThirtyMinutes) {
        _reminderTimeString = _reminderTimeString + '30分钟 ';
      } else if (i == ConsultationReminderTimeEnum.SixtyMinutes) {
        _reminderTimeString = _reminderTimeString + '60分钟 ';
      } else if (i == ConsultationReminderTimeEnum.OneDay) {
        _reminderTimeString = _reminderTimeString + '一天';
      }
      if (v.length == 4) {
        _reminderTimeString = i18nBook.common.all.t;
      }
    }
    currectReminderTimeString = _reminderTimeString;
  }

  /// 当前选中的提醒时间下标
  List<int> get currectSelectedReminderTimeIndexList =>
      _currectSelectedReminderTimeIndexList.value;
  set currectSelectedReminderTimeIndexList(List<int> v) =>
      _currectSelectedReminderTimeIndexList.value = v;

  /// 当前选中的提醒方式
  List<ConsultationReminderMode> get currectSelectedReminderMethodList =>
      _currectSelectedReminderMethodList.value;
  set currectSelectedReminderMethodList(List<ConsultationReminderMode> v) {
    _currectSelectedReminderMethodList.value = v;
    String _reminderMethodString = '';
    for (ConsultationReminderMode i in v) {
      if (i == ConsultationReminderMode.Application) {
        _reminderMethodString = i18nBook.realTimeConsultation.inAppReminder.t;
      } else if (i == ConsultationReminderMode.SMS) {
        _reminderMethodString = i18nBook.realTimeConsultation.SMSReminder.t;
      }
      if (v.length == 2) {
        _reminderMethodString = i18nBook.common.all.t;
      }
    }
    currectReminderMethodString = _reminderMethodString;
  }

  /// 当前选中的会诊时间下标
  List<int> get currectSelectedReminderMethodIndexList =>
      _currectSelectedReminderMethodIndexList.value;
  set currectSelectedReminderMethodIndexList(List<int> v) =>
      _currectSelectedReminderMethodIndexList.value = v;

  /// 多选框提醒时间的字符串值
  String get currectReminderTimeString => _currectReminderTimeString.value;
  set currectReminderTimeString(String v) =>
      _currectReminderTimeString.value = v;

  /// 多选框提醒方式的字符串值
  String get currectReminderMethodString => _currectReminderMethodString.value;
  set currectReminderMethodString(String v) =>
      _currectReminderMethodString.value = v;

  /// 提醒时间的数组
  List<FSelectSheetModel> get reminderTimeList => [
        FSelectSheetModel(
          value: ConsultationReminderTimeEnum.FifteenMinutes,
          title: i18nBook.realTimeConsultation.minBeforeStart15.t,
        ),
        FSelectSheetModel(
          value: ConsultationReminderTimeEnum.ThirtyMinutes,
          title: i18nBook.realTimeConsultation.minBeforeStart30.t,
        ),
        FSelectSheetModel(
          value: ConsultationReminderTimeEnum.SixtyMinutes,
          title: i18nBook.realTimeConsultation.minBeforeStart60.t,
        ),
        FSelectSheetModel(
          value: ConsultationReminderTimeEnum.OneDay,
          title: i18nBook.realTimeConsultation.beforeStart1day.t,
        ),
      ];

  /// 提醒方式的数组
  List<FSelectSheetModel> get reminderMethodList => [
        FSelectSheetModel(
          value: ConsultationReminderMode.Application,
          title: i18nBook.realTimeConsultation.inAppReminder.t,
        ),
        if (ServerConfigManager.isSMSOn) ...[
          FSelectSheetModel(
            value: ConsultationReminderMode.SMS,
            title: i18nBook.realTimeConsultation.SMSReminder.t,
          ),
        ],
      ];

  bool get isParticipantsListStringNullOrEmpty =>
      participantsListString == null || participantsListString == '';
}
