import {SET,SETNUMBER4,SETSELECTED4,SETCHECKBOX,ADDLABELITEM,SETCHECKTEXT,SETSEARCHDATA,
  SELECTSEARCHDATA,CHANGECHECKTEXTLABEL,CLEARCHECKBODY,CHECK_FOCUS_INDEX,CHECKBODY_CLEAR,
  SETCHECKINPUT,DEL_CHECKBODY,CHANGECHECKTEXTLABEL_NUMBER,CHECKCONFIRMSELECTED,
  CHECKBODY_MUL,DEL_CHECKBODY_LABLE,SET_CK_RADIO_INPUT_VAL,SET_IMPORT_CHECKBODY_LABEL} from '../types/checkBody.js';
import {set,setNumberValue,setRadioValue,setCheckBoxValue,addLabelItem,setCheckText,
  setSearchData,insertLabelData,changeLabelVal,clearCheckBody,setInputLabel,backspaceText,
  changeNumLabelVal,confirm,multipleComfirn,delSingleLable,setRadioInputValue,setImportCheckbodyLabel} from '../actions/checkBody.js';
import config from '@config/index.js';

const block = Object.assign(JSON.parse(config.textLabel),{full:true});//空白时保留一个自由文本标签
const initState = {
                data:[block],
                saveText:[],    //saveText为生成的纯文本
                searchData:[],
                selecteds:[],
                focusIndex:'',
                isEmpty:true,      //是否为空白，需要请求数据
                showSearchBox:false,
                importLabel:[]//[430,436,40,278,435,279,28,442,447,448,449,450,453,454,457,456,282]
          };
export default function(state=initState,action){
  let res = Object.assign({},state);
  switch(action.type){
    case SET:
      return set(state,action);
    case SETNUMBER4:
      return setNumberValue(state,action);
    case SETSELECTED4:
      return setRadioValue(state,action);
    case ADDLABELITEM:
      return addLabelItem(state,action);
    case SETCHECKTEXT:
      return setCheckText(state,action);
    case SETSEARCHDATA:
      return setSearchData(state,action);
    case SETCHECKBOX:
      return setCheckBoxValue(state,action);
    case SELECTSEARCHDATA:
      return insertLabelData(state,action);
    case CLEARCHECKBODY:
      return clearCheckBody(state,action);
    case CHANGECHECKTEXTLABEL://改变标签值
      return changeLabelVal(state,action);
    case CHECKCONFIRMSELECTED:
      return confirm(state,action);
    case CHANGECHECKTEXTLABEL_NUMBER://数字键盘
      return changeNumLabelVal(state,action);
    case CHECK_FOCUS_INDEX:
      res.focusIndex = action.index;
      res.span = action.$span;
	case CHECKBODY_CLEAR://失焦清空搜索值
      res.searchData = [];
      return res;
  case SETCHECKINPUT:
      return setInputLabel(state,action);
  case DEL_CHECKBODY:
      return backspaceText(state,action);
    case CHECKBODY_MUL:
      return multipleComfirn(state,action);
    case DEL_CHECKBODY_LABLE:
      return delSingleLable(state,action);
    case SET_CK_RADIO_INPUT_VAL:
      return setRadioInputValue(state,action);
    case SET_IMPORT_CHECKBODY_LABEL:
      return setImportCheckbodyLabel(state,action);
    default:
      return res;
  }
}