const intialState = {
    rcbPreviewData: [],
    currentImage: ""
};

const clearState = {
    rcbPreviewData: [],
};

export default (state = intialState, action) => {
    switch (action.type) {
        case "ADD_RCB_IMAGE":
            return { ...intialState, rcbPreviewData: [...state.rcbPreviewData, action.payload] };
        case "DELETE_RCB_IMAGE_BY_TITLE":
            return {
                rcbPreviewData: state.rcbPreviewData.filter(item => item.name !== action.payload)
            };
        case "SET_CURRENT_IMAGE":
            return {
                ...intialState, rcbPreviewData: [...state.rcbPreviewData], currentImage: action.payload
            }
        case "CLEAR_RCB_DATA":
            return clearState;
        default:
            return state;
    }
};
