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/PaymentOptionsModule/index.tsx
var PaymentOptionsModule_exports = {};
__export(PaymentOptionsModule_exports, {
  default: () => PaymentOptionsModule_default
});
module.exports = __toCommonJS(PaymentOptionsModule_exports);
var import_ScrollableList = __toESM(require("../ScrollableList/index"));
var import_PaymentMethodItem = __toESM(require("./PaymentMethodItem"));
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_index = require("./index.less");
var import_utils = require("@pisell/utils");
var import_ahooks = require("ahooks");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_locales = __toESM(require("../../locales"));
var import_constants = require("../../constants");
function PaymentOptionsModule({
  amountSymbol,
  orderInfo,
  onClick,
  paymentMethods = [],
  customAmount,
  title,
  disabled = false,
  showCashPayment = false,
  sciSurchargeDisplayMap = {}
}) {
  var _a, _b, _c, _d, _e, _f, _g, _h;
  const context = (0, import_useEngineContext.default)();
  import_utils.locales.init(
    import_locales.default,
    ((_f = (_e = (_d = (_c = (_b = (_a = context.appHelper) == null ? void 0 : _a.utils) == null ? void 0 : _b.getApp) == null ? void 0 : _c.call(_b)) == null ? void 0 : _d.locales) == null ? void 0 : _e.getLocale) == null ? void 0 : _f.call(_e)) || ((_h = (_g = context.appHelper.utils) == null ? void 0 : _g.storage) == null ? void 0 : _h.get("umi_locale")) || "en"
  );
  const getText = (key, fallback) => {
    var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i;
    const currentLang = ((_f2 = (_e2 = (_d2 = (_c2 = (_b2 = (_a2 = context.appHelper) == null ? void 0 : _a2.utils) == null ? void 0 : _b2.getApp) == null ? void 0 : _c2.call(_b2)) == null ? void 0 : _d2.locales) == null ? void 0 : _e2.getLocale) == null ? void 0 : _f2.call(_e2)) || ((_h2 = (_g2 = context.appHelper.utils) == null ? void 0 : _g2.storage) == null ? void 0 : _h2.get("umi_locale")) || "en";
    const checkoutText = (_i = import_locales.default[currentLang]) == null ? void 0 : _i[key];
    if (checkoutText) {
      return checkoutText;
    }
    return import_utils.locales.getText(key) || fallback;
  };
  const displayTitle = typeof title === "string" ? title : title ? String(title) : getText("cards.and.digitals", "Cards & Digitals");
  const filteredPaymentMethods = paymentMethods.filter(
    (item) => {
      var _a2;
      return !(item.type === "app" && item.code === "EFTPOS_LINKLY") && // TODO: pos 写死的这个后面权限可能要改
      ((_a2 = item.channel_application) == null ? void 0 : _a2.includes("pos")) && (["custom"].includes(item.type) || import_constants.CHECKOUT_VISIBLE_PAYMENT_CODES.includes(item.code));
    }
  );
  const { run: handlePaymentClick } = (0, import_ahooks.useDebounceFn)(
    (method) => {
      if (disabled) {
        return;
      }
      if (typeof onClick === "function") {
        onClick(method);
      }
    },
    {
      wait: 1e3,
      // 500ms 防抖延迟
      leading: true,
      trailing: false
    }
  );
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)("payment-options-module", {
        "payment-options-module-disabled": disabled
      })
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("payment-options-module-title") }, /* @__PURE__ */ import_react.default.createElement("span", null, displayTitle)),
    /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)("payment-options-module-list-container") }, /* @__PURE__ */ import_react.default.createElement(
      import_ScrollableList.default,
      {
        height: "100%",
        maxHeight: 314,
        gradientColor: "rgba(139, 92, 246, 0.1)",
        gradientHeight: 50,
        columnCount: showCashPayment ? 1 : 2,
        rowGap: 7,
        columnGap: 8,
        containerStyle: {
          width: "100%",
          flex: 1,
          // 使用flex来占用剩余空间
          minHeight: 0,
          // 允许缩小
          position: "relative",
          // 确保定位上下文
          paddingBottom: 8
        }
      },
      filteredPaymentMethods.map((method) => /* @__PURE__ */ import_react.default.createElement(
        import_PaymentMethodItem.default,
        {
          size: (filteredPaymentMethods == null ? void 0 : filteredPaymentMethods.length) === 2 ? "large" : "default",
          key: method.id,
          method,
          amountSymbol,
          customAmount,
          disabled,
          onClick: handlePaymentClick,
          getText,
          surchargeDisplay: sciSurchargeDisplayMap[String(method.id)]
        }
      ))
    ))
  );
}
var PaymentOptionsModule_default = PaymentOptionsModule;
