{"size": 919, "ext": "js", "max_stars_repo_path": "src/contexts/chat/reducer.js", "max_stars_repo_name": "feds01/durak-cards-client", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/contexts/chat/reducer.js", "max_issues_repo_name": "feds01/durak-cards-client", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/contexts/chat/reducer.js", "max_forks_repo_name": "feds01/durak-cards-client", "max_forks_repo_forks_event_min_datetime": "2021-01-22T21:20:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-22T21:20:44.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 27.8484848485, "max_line_length": 107, "alphanum_fraction": 0.5397170838}
export const initialState = {
    messages: [],
    opened: false,
    disabled: false,
    unreadCount: 0,
};

export function init({disabled, messages}) {
    return {...initialState, messages, disabled};
}

export const reducer = (initialState, action) => {
    switch (action.type) {
        case "PUT_MESSAGE": {
            return {
                ...initialState,
                messages: [...initialState.messages, action.message],
                unreadCount: initialState.opened ? initialState.unreadCount : initialState.unreadCount + 1,
            };
        }
        case "TOGGLE_CHAT": {
            return {
                ...initialState,
                unreadCount: !initialState.opened ? 0 : initialState.unreadCount,
                opened: !initialState.opened,
            }
        }
        default: {
            throw new Error(`Unhandled action type: ${action.type}`);
        }
    }
};
