import {
    HISTORY_TEMPLATES,
    HISTORY_TEMPLATES_SORT,
    HISTORY_INIT,
    HISTORY_ACTIVE,
    HISTORY_VISIBLE,
    HISTORY_UPDATEBYIDUSNAMES,
    HISTORY_GETHOSPITALINFO,
    HISTORYID
} from '../types/historyTemplates';


const initHistoryList = {
    showHistoryCases: false,//历史病历显示隐藏
    visible:false,
    activeHistory:{},//需要显示的病例
    items: [],
    HospitalInfo: {}, // 医院信息
    historyId: -1, // 病历id
}

export default (state = initHistoryList, action) => {
    if (action.type === HISTORY_TEMPLATES) {
        const newState = Object.assign({}, state);
        newState.showHistoryCases = action.bool;
        return newState;
    }
    if (action.type === HISTORY_TEMPLATES_SORT) {
        const newState = Object.assign({}, state);
        const tempArr = newState.items.reverse()
        newState.items = [...tempArr];
        return newState;
    }
    if (action.type === HISTORY_INIT) {
        const newState = Object.assign({}, state);
        const tempArr = action.data.records || [];
        newState.items = [...tempArr];
        newState.activeHistory = tempArr[0];
        return newState;
    }
    if (action.type === HISTORY_ACTIVE) {
        const newState = Object.assign({}, state);
        const tempArr = newState.items[action.idx]
        newState.activeHistory = tempArr;
        return newState;
    }
    if (action.type === HISTORY_VISIBLE) {
        const newState = Object.assign({}, state);
        newState.visible = action.bool;
        return newState;
    }
    if (action.type === HISTORY_UPDATEBYIDUSNAMES) {
        const newState = Object.assign({}, state);
        // console.log(newState,'newState');
        return newState;
    }

    if (action.type === HISTORY_GETHOSPITALINFO) {
        const newState = Object.assign({}, state);
        newState.HospitalInfo = action.data
        return newState;
    }
     if (action.type === HISTORYID) {
       const newState = Object.assign({}, state);
       newState.historyId = action.id;
       return newState;
     }

    return state;
}
