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/pay/toB/paymentMethods/index.tsx
var paymentMethods_exports = {};
__export(paymentMethods_exports, {
  default: () => paymentMethods_default
});
module.exports = __toCommonJS(paymentMethods_exports);
var import_react = __toESM(require("react"));
var import_EFTPOS = __toESM(require("../components/EFTPOS"));
var import_MX51 = __toESM(require("../components/MX51"));
var import_useLogger = __toESM(require("../../../../hooks/useLogger"));
var PaymentMethods = (props, ref) => {
  const eftposRef = (0, import_react.useRef)(null);
  const mx51Ref = (0, import_react.useRef)(null);
  const logger = (0, import_useLogger.default)();
  const onPay = (type, params) => {
    var _a, _b, _c, _d;
    const { callback, ...otherParams } = params;
    console.log("onPay_params>>>>", type, params);
    logger == null ? void 0 : logger.addLog({
      type: "info",
      title: "ToB_PaymentMethods_onPay 开始调用",
      metadata: { type, params }
    });
    if (type === "eftpos") {
      (_b = (_a = eftposRef.current) == null ? void 0 : _a.open) == null ? void 0 : _b.call(_a, {
        ...otherParams,
        payCallback: (res) => _eftpcallback(res, callback)
      });
    } else if (type === "mx51") {
      (_d = (_c = mx51Ref.current) == null ? void 0 : _c.open) == null ? void 0 : _d.call(_c, {
        ...otherParams,
        payCallback: (res) => _mx51callback(res, callback)
      });
    }
  };
  const _eftpcallback = (res, callback) => {
    const params = { status: res.status, data: res.params };
    logger == null ? void 0 : logger.addLog({
      type: "info",
      title: "ToB_PaymentMethods_eftpos_callback",
      metadata: { res, params }
    });
    callback(params);
  };
  const _mx51callback = (res, callback) => {
    const params = {
      status: res.result ? "success" : "fail",
      data: {
        amount: res.amount,
        surcharge: res.surcharge,
        uniquePaymentNumber: res.uniquePaymentNumber
      },
      msg: res.msg
    };
    logger == null ? void 0 : logger.addLog({
      type: "info",
      title: "ToB_PaymentMethods_mx51_callback",
      metadata: { res, params }
    });
    callback(params);
  };
  (0, import_react.useImperativeHandle)(ref, () => ({
    onPay
  }));
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_EFTPOS.default,
    {
      ref: eftposRef,
      dynamicMaxHeight: props == null ? void 0 : props.dynamicMaxHeight,
      isWebPos: props == null ? void 0 : props.isWebPos
    }
  ), /* @__PURE__ */ import_react.default.createElement(import_MX51.default, { ref: mx51Ref }));
};
var paymentMethods_default = (0, import_react.forwardRef)(PaymentMethods);
