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/payment-modal-utils.ts
var payment_modal_utils_exports = {};
__export(payment_modal_utils_exports, {
  calculateAutoCloseConfig: () => calculateAutoCloseConfig,
  calculateStatusClassName: () => calculateStatusClassName,
  calculateSubtitle: () => calculateSubtitle,
  calculateTitle: () => calculateTitle,
  formatCurrency: () => formatCurrency,
  getSubtitleClassName: () => getSubtitleClassName
});
module.exports = __toCommonJS(payment_modal_utils_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var formatCurrency = (amount, amountSymbol = "$") => {
  return (0, import_utils.formatAmount)(amount, 2, amountSymbol);
};
var calculateTitle = (status, failureReason, getText = () => "") => {
  switch (status) {
    case "paid":
    case "partially_paid":
      return getText("payment.result.success");
    case "failed":
      const reason = failureReason ? ` - ${failureReason}` : "";
      return `${getText("payment.result.failed")}${reason}`;
    case "wallet-pass-redemption-failed":
      return getText("pisell2.checkout.wallet-pass.redemption-failed") || "Wallet pass redeem failed";
    default:
      return getText("payment.result.success");
  }
};
var getSubtitleClassName = (colorClass) => {
  return `payment-result-toast-subtitle-text ${colorClass}`;
};
var calculateSubtitle = (status, amount, gapAmount, getText = () => "", amountSymbol = "$") => {
  let text;
  let colorClass;
  switch (status) {
    case "paid":
      if (gapAmount) {
        text = `${getText("payment.result.changeDue") || "Change Due"} ${formatCurrency(Math.abs(gapAmount), amountSymbol)}`;
        colorClass = "partially-paid";
      } else {
        text = `${getText("payment.result.paid") || "Paid"} ${formatCurrency(amount, amountSymbol)}`;
        colorClass = "paid";
      }
      break;
    case "partially_paid":
      const displayAmount = gapAmount ?? amount;
      text = `${getText("payment.result.partiallyPaid") || "Partially Paid"} ${formatCurrency(displayAmount, amountSymbol)}`;
      colorClass = "partially-paid";
      break;
    case "failed":
      text = `${getText("payment.result.amountDue") || "Amount Due"} ${formatCurrency(amount, amountSymbol)}`;
      colorClass = "amount-due";
      break;
    case "wallet-pass-redemption-failed":
      const successAmount = gapAmount ?? amount;
      text = `${getText("payment.result.partiallyPaid") || "Partially Paid"} ${formatCurrency(successAmount, amountSymbol)}`;
      colorClass = "partially-paid";
      break;
    default:
      return null;
  }
  return import_react.default.createElement(
    "div",
    { className: "payment-result-toast-subtitle" },
    import_react.default.createElement(
      "h1",
      { className: getSubtitleClassName(colorClass) },
      text
    )
  );
};
var calculateStatusClassName = (status) => {
  switch (status) {
    case "paid":
    case "partially_paid":
      return "success";
    case "failed":
      return "failed";
    case "wallet-pass-redemption-failed":
      return "wallet-pass-failed";
    default:
      return "success";
  }
};
var calculateAutoCloseConfig = (status, hasChangeDue) => {
  switch (status) {
    case "paid":
      return {
        autoClose: true,
        autoCloseDelay: hasChangeDue ? 30 : 5,
        // 有找零30秒，无找零5秒
        maskClosable: true
      };
    case "partially_paid":
      return {
        autoClose: true,
        autoCloseDelay: 5,
        maskClosable: true
      };
    case "failed":
    case "wallet-pass-redemption-failed":
      return {
        autoClose: false,
        autoCloseDelay: 0,
        maskClosable: false
      };
    default:
      return {
        autoClose: false,
        autoCloseDelay: 5,
        maskClosable: false
      };
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  calculateAutoCloseConfig,
  calculateStatusClassName,
  calculateSubtitle,
  calculateTitle,
  formatCurrency,
  getSubtitleClassName
});
