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


const initHistoryList = {
    showHistoryCases: false,     //历史病历显示隐藏
    visible:false,
    activeHistory:{},     //需要显示的病例
    items: []
}

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 || [];
        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;
    }
    return state;
}
