import { createAction } from "redux-actions";

import {
  TOAST_DURATION,
  TOAST_HIDE,
  TOAST_SHOW,
} from "../constants/toast";

const showToast = createAction(TOAST_SHOW, (message, type) => ({ message, type }));
const hideToast = createAction(TOAST_HIDE);

export const showToastMessage = (message, type = "success") => (dispatch) => {
  dispatch(showToast(message, type));
  setTimeout(() => dispatch(hideToast()), TOAST_DURATION);
};

export const hideToastMessage = () => (dispatch) => {
  dispatch(hideToast());
};
