import { useEffect, useRef } from "react";
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
import Toast from "@arcblock/ux/lib/Toast";
export default function StatusFeedback({ status, context, onReset }) {
  const { t } = useLocaleContext();
  const prevStatusRef = useRef(status);
  useEffect(() => {
    if (status === prevStatusRef.current) return;
    prevStatusRef.current = status;
    if (status === "failed" && context?.type === "error") {
      if (context.code === "CUSTOMER_LIMITED" || context.code === "STOP_ACCEPTING_ORDERS") return;
      Toast.error(context.message || "Payment failed");
      onReset();
    }
  }, [status, context, t, onReset]);
  return null;
}
