const defaultState = {
    count: 0,
    list: []
}

const layout = (state = defaultState, action) => {
    switch (action.type) {
        case 'SET_NOTICE_COUNT':
            {
                const _state = {
                    ...state,
                    count: action.count
                }
                return _state
            }
        case 'SET_NOTICE_LIST':
            {
                const _state = {
                    ...state,
                    list: action.list
                }
                return _state
            }
        case 'READ_NOTICE':
            {
                const notice = state.list.find(p => p.id === action.id)
                if (notice && !notice.readStatus) {
                    notice.readStatus = 1
                    state.count -= 1
                }
                return {
                    ...state
                }
            }
        default:
            return state
    }
}

export default layout