import { createSlice } from '@reduxjs/toolkit';

export const slice = createSlice({
    name: 'userInfo',
    initialState: {
        tokenInfo: null,
        user: {},
        regularNum: 0,
        rulerNum: 0,
        problemNum: 0,
        lossNum: 0,
		diagNum: 0,
		docNum: 0,
		drugNum: 0,
		dutyNum: 0,
		surgeryNum: 0
    },
    reducers: {
        add: (state, action) => {        //添加token
            state.tokenInfo = action.payload;
        },
        remove: (state) => {        //删除token
            state.tokenInfo = null;
        },
        setSys: (state, action) => {        //选中的系统和医院id
            const { sysId, sysName, hisId } = action.payload;
            state.sysId = sysId;
            state.sysName = sysName;
            state.hisId = hisId;
        },
        setUser: (state, action) => {        //删除token
            state.user = action.payload;
        },
        setUnReadNum(state, action) {     //未读消息数量
            state.unReadNum = action.payload;
        },
        setRegularNum(state, action) {
            state.regularNum = action.payload;
        },
        setRulerNum(state, action) {
            state.rulerNum = action.payload;
        },
        setProblemNum(state, action) {
            state.problemNum = action.payload;
        },
        setLossNum(state, action) {
            state.lossNum = action.payload;
        },
		setDiagNum(state, action) {
		    state.diagNum = action.payload;
		},
		setDocNum(state, action) {
		    state.docNum = action.payload;
		},
		setDrugNum(state, action) {
		    state.drugNum = action.payload;
		},
		setDutyNum(state, action) {
		    state.dutyNum = action.payload;
		},
		setSurgeryNum(state, action) {
		    state.surgeryNum = action.payload;
		}
    },
});

export const { remove, add, setSys, setUser, setUnReadNum, setRegularNum, setRulerNum, setProblemNum, setLossNum, setDiagNum, setDocNum, setDrugNum, setDutyNum, setSurgeryNum } = slice.actions;

export default slice.reducer;
