import { AnyAction } from "redux";
import { Cart } from "../../model/cart";
import productSaga from '../sagas/productSaga';
import Types from '../types'


const initState: Cart = {
    products: []
}

function cartReducer(state: Cart = initState, action: AnyAction) {
    const payload = action.payload
    switch (action.type) {
        case Types.ADD_PRODUCT_TO_CART:
            const products = state.products
            return {
                ...state,
                products: [payload, ...products],
            };
        default:
            return state
    }
}

export default cartReducer