export const MEDICAL_DICTIONARY_TYPES = Object.freeze({
  PRIMARY_DISEASE: 'PRIMARY_DISEASE',
  HYDROCEPHALUS_TYPE: 'HYDROCEPHALUS_TYPE',
  SHUNT_MODE: 'SHUNT_MODE',
  PROXIMAL_PUNCTURE_AREA: 'PROXIMAL_PUNCTURE_AREA',
  VALVE_PLACEMENT_SITE: 'VALVE_PLACEMENT_SITE',
  DISTAL_SHUNT_DIRECTION: 'DISTAL_SHUNT_DIRECTION',
});

export const MEDICAL_DICTIONARY_TYPE_OPTIONS = Object.freeze([
  {
    label: '原发病',
    value: MEDICAL_DICTIONARY_TYPES.PRIMARY_DISEASE,
    optionKey: 'primaryDiseaseOptions',
  },
  {
    label: '脑积水类型',
    value: MEDICAL_DICTIONARY_TYPES.HYDROCEPHALUS_TYPE,
    optionKey: 'hydrocephalusTypeOptions',
  },
  {
    label: '分流方式',
    value: MEDICAL_DICTIONARY_TYPES.SHUNT_MODE,
    optionKey: 'shuntModeOptions',
  },
  {
    label: '近端穿刺区域',
    value: MEDICAL_DICTIONARY_TYPES.PROXIMAL_PUNCTURE_AREA,
    optionKey: 'proximalPunctureOptions',
  },
  {
    label: '阀门植入部位',
    value: MEDICAL_DICTIONARY_TYPES.VALVE_PLACEMENT_SITE,
    optionKey: 'valvePlacementOptions',
  },
  {
    label: '远端分流方向',
    value: MEDICAL_DICTIONARY_TYPES.DISTAL_SHUNT_DIRECTION,
    optionKey: 'distalShuntDirectionOptions',
  },
]);

export function createEmptyMedicalDictionaryOptions() {
  return {
    primaryDiseaseOptions: [],
    hydrocephalusTypeOptions: [],
    shuntModeOptions: [],
    proximalPunctureOptions: [],
    valvePlacementOptions: [],
    distalShuntDirectionOptions: [],
  };
}

export function groupMedicalDictionaryItems(items) {
  const grouped = createEmptyMedicalDictionaryOptions();

  MEDICAL_DICTIONARY_TYPE_OPTIONS.forEach((typeOption) => {
    grouped[typeOption.optionKey] = [];
  });

  (Array.isArray(items) ? items : []).forEach((item) => {
    const typeOption = MEDICAL_DICTIONARY_TYPE_OPTIONS.find(
      (option) => option.value === item.type,
    );
    if (!typeOption || !item.enabled) {
      return;
    }

    grouped[typeOption.optionKey].push(item.label);
  });

  return grouped;
}
