import { CHAT_CLEAR, CHAT_ONE_SET, CHAT_SET } from "../../actions/chat/chatActionConstants"
import createReducer from "../../utils/createReducer"

const initialState = {
    latestChats: [],
    selectedChat: {}
}

export default createReducer(
    {
        [CHAT_SET]: setChats,
        [CHAT_ONE_SET]: setOneChat,
        [CHAT_CLEAR]: clearChats
    },
    initialState
)

function setChats(state, action) {
    return {
        ...state,
        latestChats: [...action.payload]
    }
}
function setOneChat(state, action) {
    return {
        ...state,
        selectedChat: action.payload
    }
}
function clearChats() {
    return initialState;
}