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

const toastSlice = createSlice({
  name: "toast",
  initialState: {
    message: "",
    type: "success", // success | error | warning | info
    visible: false,
  },
  reducers: {
    showToast(state, action) {
      const { message, type } = action.payload;
      state.message = message;
      state.type = type || "success";
      state.visible = true;
    },
    hideToast(state) {
      state.visible = false;
    },
    clearToast(state) {
      state.message = "";
      state.type = "success";
      state.visible = false;
    },
  },
});

export const { showToast, hideToast, clearToast } = toastSlice.actions;
export default toastSlice.reducer;
