import { createSlice } from "@reduxjs/toolkit";

export const toastConfig = {
  icon: null, // "danger", "warning", "info", "success"
  message: null,
  duration: 3000,
};

export const toastSlice = createSlice({
  name: "toast",
  initialState: {
    toast: [],
  },
  reducers: {
    addToast: (state, action) => {
      state.toast = [
        { ...action.payload, id: crypto.randomUUID() },
        ...state.toast,
      ];
    },

    deleteToastById: (state, action) => {
      state.toast = state.toast.filter((item) => item.id !== action.payload);
    },
  },
  selectors: {
    selectToast: (state) => state.toast,
  },
});

export const { addToast, deleteToastById } = toastSlice.actions;
export const { selectToast } = toastSlice.selectors;

export default toastSlice.reducer;
