import {
  ADD_DIAGNOSTIC,
  DEL_DIAGNOSTIC,
  UP_DIAGNOSTIC,
  DOWN_DIAGNOSTIC,
  SET_TREAT,
  GET_DIAGNOSTIC_STR,
  SET_DIAG_TO_MAINSUIT,
  GET_IS_FIRST,
  CLEAR_ALL_DIAG,
  SET_CLICK_DIAG,
  CLEAR_DIAGNOSE,
  SET_CHRONIC_MAG_ITEM,
  SHOW_REFER_RECORD,
  HIDE_REFER_RECORD,
  SHOW_HISTORY_CASE,
  HIDE_HISTORY_CASE,
  SHOW_LOADING,
  ADD_TREAT,
  REDIAGDATA,
  CLEARDIAGDATA,
  ADDDIAGMSG,
  EDITDIAGMSG,
} from '../types/diagnosticList';
import {
  addDiagnostic,
  addTcmDiagnostic,
  delDiagnostic,
  upDiagnostic,
  downDiagnostic,
  setTreat,
  getDiagnosticStr,
  setDiagToMainSuit,
  getIsFirst,
  clearAllDiag,
  setClickDiag,
  setChronicMagItem,
  showReferRecord,
  hideReferRecord,
  showHistoryCase,
  hideHistoryCase,
  addTreat,
  reDiagData,
  addDiagMsg,
  editDiagMsg
} from '../actions/diagnosticList';

const initState = {
    isFirst: true,
    diagnosticList: [
    
    ],
    tcmList:[],
    mainSuitStr:'',
    diagnosticStrNoType:'',
    diagnosticStr:'',
    diseaseName: {
      
    },
    otherIndex:{}
}

export default function (state=initState, action) {
    const res = Object.assign({},state);
    switch (action.type) {
      case EDITDIAGMSG:
        return editDiagMsg(state, action);
      case ADDDIAGMSG:
        return addDiagMsg(state, action);
      case ADD_DIAGNOSTIC:
        if(action.isTcm){
            return addTcmDiagnostic(state, action);
        }
        return addDiagnostic(state, action);
      case DEL_DIAGNOSTIC:
        return delDiagnostic(state, action);
      case UP_DIAGNOSTIC:
        return upDiagnostic(state, action);
      case DOWN_DIAGNOSTIC:
        return downDiagnostic(state, action);
      case SET_TREAT:
        return setTreat(state, action);
      case GET_DIAGNOSTIC_STR:
        return getDiagnosticStr(state, action);
      case SET_DIAG_TO_MAINSUIT:
        return setDiagToMainSuit(state, action);
      case GET_IS_FIRST:
        return getIsFirst(state, action);
      case CLEAR_ALL_DIAG:
        return clearAllDiag(state, action);
      case SET_CLICK_DIAG:
        return setClickDiag(state, action);
      case SET_CHRONIC_MAG_ITEM:
        return setChronicMagItem(state, action);
      case SHOW_REFER_RECORD:
        return showReferRecord(state, action);
      case HIDE_REFER_RECORD:
        return hideReferRecord(state, action);
      case SHOW_HISTORY_CASE:
        return showHistoryCase(state, action);
      case HIDE_HISTORY_CASE:
        return hideHistoryCase(state, action);
      case ADD_TREAT:
        return addTreat(state, action);
      case CLEAR_DIAGNOSE:
        res.mainSuitStr = '';
        return res;
      case SHOW_LOADING:
        res.loading = action.flag;
        return res;
      case REDIAGDATA:
        return reDiagData(state, action);
      case CLEARDIAGDATA:
        let newState = Object.assign({}, state);
        newState.diagnosticStr = '';
        newState.diagnosticList = [];
        newState.diseaseName = {};
        newState.diagnosticStrNoType = '';
        return newState;
      case 'CLEARTCMDIAGDATA':
          let newSt = Object.assign({}, state);
          newSt.otherIndex={};
          newSt.tcmList=[];
          return newSt;
      default:
        return state;
    }
}
