import {createContext, useReducer} from "react";

export const ToastContext = createContext()

const reducer = (state, action) => {
    switch (action.type) {
        case "PUSH":
            return {
                ...state,
                [action.toast_type]: [...state[action.toast_type], action.toast_id]
            };
    }
};

export const ToastProvider = ({children}) => {
    const [state, dispatch] = useReducer(reducer, {
        pending: [],
        error: [],
        warning: [],
        success: []
    });

    console.log(state)

    return (
        <ToastContext.Provider value={{state, dispatch}}>
            {children}
        </ToastContext.Provider>
    );
};
