var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/checkout/components/PaymentResultToast/PaymentResultToastProvider.tsx
var PaymentResultToastProvider_exports = {};
__export(PaymentResultToastProvider_exports, {
  PaymentResultToastProvider: () => PaymentResultToastProvider,
  closePaymentResultToast: () => closePaymentResultToast,
  showPaymentResultToast: () => showPaymentResultToast,
  showPaymentResultToastFailed: () => showPaymentResultToastFailed,
  showPaymentResultToastSuccess: () => showPaymentResultToastSuccess,
  showPaymentResultToastWalletPassFailed: () => showPaymentResultToastWalletPassFailed,
  usePaymentResultToast: () => usePaymentResultToast
});
module.exports = __toCommonJS(PaymentResultToastProvider_exports);
var import_react = __toESM(require("react"));
var import_react_dom = require("react-dom");
var import_index = __toESM(require("./index"));
var PaymentResultToastContext = (0, import_react.createContext)(null);
var globalPaymentResultToastContext = null;
var DEFAULT_TOAST_CONFIG = {
  width: 680,
  mask: true,
  maskClosable: false,
  closable: true,
  zIndex: 2e3
};
var PaymentResultToastProvider = ({ children }) => {
  const [toastProps, setToastProps] = (0, import_react.useState)(null);
  const customOnCloseRef = (0, import_react.useRef)();
  const customOnCountdownCompleteRef = (0, import_react.useRef)();
  const closeToast = (0, import_react.useCallback)(() => {
    setToastProps(null);
  }, []);
  const handleClose = (0, import_react.useCallback)(() => {
    var _a;
    (_a = customOnCloseRef.current) == null ? void 0 : _a.call(customOnCloseRef);
    closeToast();
  }, [closeToast]);
  const handleCountdownComplete = (0, import_react.useCallback)(() => {
    var _a;
    (_a = customOnCountdownCompleteRef.current) == null ? void 0 : _a.call(customOnCountdownCompleteRef);
  }, []);
  const showToast = (0, import_react.useCallback)((config) => {
    customOnCloseRef.current = config.onClose;
    customOnCountdownCompleteRef.current = config.onCountdownComplete;
    const finalConfig = {
      ...DEFAULT_TOAST_CONFIG,
      visible: true,
      statusClassName: config.statusClassName,
      title: config.title,
      subtitle: config.subtitle,
      changeDueText: config.changeDueText,
      actionButtons: config.actionButtons || [],
      autoClose: config.autoClose,
      autoCloseDelay: config.autoCloseDelay || 5,
      showCountdownProgress: config.showCountdownProgress,
      onCountdownComplete: handleCountdownComplete,
      // 使用稳定的handleCountdownComplete函数
      onClose: handleClose
      // 使用稳定的handleClose函数
    };
    setToastProps(finalConfig);
  }, [handleClose, handleCountdownComplete]);
  const showSuccess = (0, import_react.useCallback)((config) => {
    showToast({ ...config, statusClassName: "success" });
  }, [showToast]);
  const showFailed = (0, import_react.useCallback)((config) => {
    showToast({ ...config, statusClassName: "failed" });
  }, [showToast]);
  const showWalletPassFailed = (0, import_react.useCallback)((config) => {
    showToast({ ...config, statusClassName: "wallet-pass-failed" });
  }, [showToast]);
  const isVisible = !!(toastProps == null ? void 0 : toastProps.visible);
  const contextValue = {
    showSuccess,
    showFailed,
    showWalletPassFailed,
    showToast,
    closeToast,
    isVisible
  };
  (0, import_react.useEffect)(() => {
    globalPaymentResultToastContext = contextValue;
    return () => {
      globalPaymentResultToastContext = null;
    };
  }, [contextValue]);
  return /* @__PURE__ */ import_react.default.createElement(PaymentResultToastContext.Provider, { value: contextValue }, children, toastProps && (0, import_react_dom.createPortal)(
    /* @__PURE__ */ import_react.default.createElement(import_index.default, { ...toastProps }),
    document.body
  ));
};
var usePaymentResultToast = () => {
  const context = (0, import_react.useContext)(PaymentResultToastContext);
  if (!context) {
    throw new Error("usePaymentResultToast must be used within a PaymentResultToastProvider");
  }
  return context;
};
var showPaymentResultToastSuccess = (config) => {
  if (globalPaymentResultToastContext) {
    globalPaymentResultToastContext.showSuccess(config);
  } else {
    console.error("PaymentResultToastProvider not found. Please wrap your app with PaymentResultToastProvider.");
  }
};
var showPaymentResultToastFailed = (config) => {
  if (globalPaymentResultToastContext) {
    globalPaymentResultToastContext.showFailed(config);
  } else {
    console.error("PaymentResultToastProvider not found. Please wrap your app with PaymentResultToastProvider.");
  }
};
var showPaymentResultToastWalletPassFailed = (config) => {
  if (globalPaymentResultToastContext) {
    globalPaymentResultToastContext.showWalletPassFailed(config);
  } else {
    console.error("PaymentResultToastProvider not found. Please wrap your app with PaymentResultToastProvider.");
  }
};
var showPaymentResultToast = (config) => {
  if (globalPaymentResultToastContext) {
    globalPaymentResultToastContext.showToast(config);
  } else {
    console.error("PaymentResultToastProvider not found. Please wrap your app with PaymentResultToastProvider.");
  }
};
var closePaymentResultToast = () => {
  if (globalPaymentResultToastContext) {
    globalPaymentResultToastContext.closeToast();
  } else {
    console.error("PaymentResultToastProvider not found.");
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PaymentResultToastProvider,
  closePaymentResultToast,
  showPaymentResultToast,
  showPaymentResultToastFailed,
  showPaymentResultToastSuccess,
  showPaymentResultToastWalletPassFailed,
  usePaymentResultToast
});
