import {HIDE,RESET,SETINITDATA,SETDROPSHOW,SETADDITEMINIT,SETT0EDIT,SETREADDITEMS,
  HIDEDROP,CLICKCOUNT,ISREAD,SETOTHERHISTORY,SETMINSCREEN,MODI_LOADING,SEARCH_DROP_LOCATION,GET_INSPECT_LIST,GET_ASSIST_LIST,SETALLMODULES} from '../types/homePage.js';
import {showDrop,setAddItemInit,setLabelToEdit,confirmHide,clickNum,searchDropLocation,getInspectList,getAssistList} from '../actions/homePage.js';
import SearchDrop from '../../components/SearchDrop/index.jsx';

const initState = {
  totalHide:false,
  initData:{},
  showDrop:{},
  focusTextIndex:'',
  clickData:[],
  addItems:{},
  commSymHide:false,
  loadingFlag:true,
  boxTop:0,
  boxLeft:0,
  allModules:[],
  assistList:[],
  inspectList:[],
};

export default function (state=initState,action) {
  let res = Object.assign({},state);
  switch (action.type){
    case HIDE:
      res.totalHide = true;
      return res;
    case RESET:
      res.totalHide = false;
      res.commSymHide = false;
      return res;
    case SETDROPSHOW:
      return showDrop(state,action);
    case HIDEDROP:
      return confirmHide(state,action);
    case SETINITDATA:
      res.initData = action.data;
      return res;
    case CLICKCOUNT:
      return clickNum(state,action);
    case SETADDITEMINIT:
      return setAddItemInit(state,action);
    case SETT0EDIT:
      return setLabelToEdit(state,action);
    case SETREADDITEMS:
      res.addItems = action.data||{};
      return res;
    case ISREAD:
      res.isRead = Math.random();
      return res;
    case SETOTHERHISTORY:
      res.initData.otherHis = action.data;
      res.initData.otherHisSave = action.save;
      res.initData.otherSelecteds = action.selecteds||[];
      res.initData.otherIsHis = action.otherIsHis!=undefined?action.otherIsHis:true;
      res.initData.period = action.period;
      return res;
    /*case SETTEXTFOCUS:
      res.focusTextIndex = action.index;
      res.span=action.$span;
      return res;*/
    case SETMINSCREEN:
      res.windowWidth = action.obj.width;
      res.windowHeight = action.obj.height;
      return res;
    case MODI_LOADING:
      // res.loadingFlag = false;
      res.loadingFlag = action.flag;
      return res;
    case SEARCH_DROP_LOCATION:
      return searchDropLocation(state,action);
    case GET_INSPECT_LIST:
      return getInspectList(state,action);
    case GET_ASSIST_LIST:
      return getAssistList(state,action);
    case SETALLMODULES:
      res.allModules = action.data;
      return res;
    default:
      return res;
  }
}