import {SETDATA,CONFIRMSELECTED,SETRADIO,SETNUMBER,SETOTHERCHECKBOX,SETOTHERTEXT,SETOTHERSEARCHDATA,
  SELECTOTHERSEARCHDATA,CLEAROTHERHISTORY,CHANGEOTHERTEXTLABEL,SETOTHERINPUT,SETTEXTMODEVALUE,OTHER_FOCUS_INDEX,OTHERHIS_CLEAR,
  OTHERADDLABELITEM,OTHEREDICLEAR,DEL_OTHERHIS,CHANGEOTHERTEXTLABEL_NUMBER,OTHERHIS_MUL,REMOVE_OTHER_ID,DEL_OTHERHIS_LABLE,SET_OT_RADIO_INPUT_VAL} from '../types/otherHistory';
import {confirm,setRadioValue,setNumberValue,setCheckBoxValue,setCheckText,setSearchData,insertLabelData,clearOtherHistory,
  changeTextLabel,setOtherInput,setTextModeValue,addLabelItem,otherEditClear,backspaceText,changeNumLabelVal,multipleComfirn,
  removeId,delSingleLable,setRadioInputValue} from '../actions/otherHistory';
import config from '@config/index.js';

const block = Object.assign(JSON.parse(config.textLabel),{full:true});//空白时保留一个自由文本标签
const initState = {data:[block],isEmpty:true,saveText:[],selecteds:[],focusIndex:'',editClear:true};/*mockData.OtherHis.moduleDetailDTOList;[
    mockData.radioData,
    mockData.inputData,
    mockData.spreadData,
    mockData.inpRadioData,
    mockData.spreadMultData,
  ];*/

export default function(state=initState,action){//console.log(state)
  const res = Object.assign({},state);
  switch (action.type){
    case SETDATA:
      res.data = action.data;
      res.selecteds = action.selecteds||[];
      const period = action.period;
      if(period){
        res.yjs_1=period.yjs_1;
        res.yjs_2=period.yjs_2;
        res.yjs_3=period.yjs_3;
        res.yjs_4=period.yjs_4;
      }
      res.saveText = action.save||[];
      res.isEmpty = action.isEmpty;
      return res;
    case SETRADIO:
      return setRadioValue(state,action);
    case SETNUMBER:
      return setNumberValue(state,action);
    case CONFIRMSELECTED:
      return confirm(state,action);
    case SETOTHERTEXT:
      return setCheckText(state,action);
    case SETOTHERSEARCHDATA:
      return setSearchData(state,action);
    case SETOTHERCHECKBOX:
      return setCheckBoxValue(state,action);
    case SELECTOTHERSEARCHDATA:
      return insertLabelData(state,action);
    case CLEAROTHERHISTORY:
      return clearOtherHistory(state,action);
    case CHANGEOTHERTEXTLABEL:
      return changeTextLabel(state,action);
    case CHANGEOTHERTEXTLABEL_NUMBER:
      return changeNumLabelVal(state,action);
    case SETOTHERINPUT:
      return setOtherInput(state,action);
    case SETTEXTMODEVALUE:
      return setTextModeValue(state,action);
    case OTHERADDLABELITEM:
      return addLabelItem(state,action);
    case OTHER_FOCUS_INDEX:
      res.focusIndex = action.index;
      res.span = action.$span;
    case OTHERHIS_CLEAR:
        res.searchData = [];
        return res;
    case OTHEREDICLEAR:
        return otherEditClear(state,action);
    case DEL_OTHERHIS:
        return backspaceText(state,action);
    case OTHERHIS_MUL:
        return multipleComfirn(state,action);
    case REMOVE_OTHER_ID:
        return removeId(state,action);
    case DEL_OTHERHIS_LABLE:
        return delSingleLable(state,action);
    case SET_OT_RADIO_INPUT_VAL:
      return setRadioInputValue(state,action);
    default:
      return res;
  }
}