import { jsx } from "react/jsx-runtime";
import { useEffect, memo } from "react";
import { ToastPosition, ToastType, DSToast, toast } from "@elliemae/ds-toast";
import { useAppSelector, useAppDispatch } from "../../data/react.js";
import { actions as error } from "../../data/error/index.js";
const ErrorToast = memo((props) => {
  const storeError = useAppSelector((state) => state?.error);
  const dispatch = useAppDispatch();
  useEffect(() => {
    if (storeError && (storeError?.description || storeError?.messageText)) {
      const toastProps = {
        position: ToastPosition.TOP_RIGHT,
        messageTitle: "Error",
        type: ToastType.ERROR,
        ...props,
        ...storeError
      };
      const messageText = toastProps.description || toastProps.messageText;
      if (messageText) toast({ messageText, ...toastProps }, {});
      dispatch(error.clear());
    }
  }, [storeError, props, dispatch]);
  return /* @__PURE__ */ jsx(DSToast, { ...props });
});
export {
  ErrorToast
};
