function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _excluded = ["callback"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
import EFTPOS from "../components/EFTPOS";
import MX51 from "../components/MX51";
import useLogger from "../../../../hooks/useLogger";

// 定义 MX51 组件暴露的方法类型

// 定义 PaymentMethods 组件暴露的方法类型

var PaymentMethods = function PaymentMethods(props, ref) {
  var eftposRef = useRef(null);
  var mx51Ref = useRef(null);
  var logger = useLogger();
  var onPay = function onPay(type, params) {
    var callback = params.callback,
      otherParams = _objectWithoutProperties(params, _excluded);
    console.log('onPay_params>>>>', type, params);
    logger === null || logger === void 0 || logger.addLog({
      type: 'info',
      title: 'ToB_PaymentMethods_onPay 开始调用',
      metadata: {
        type: type,
        params: params
      }
    });
    if (type === 'eftpos') {
      var _eftposRef$current, _eftposRef$current$op;
      (_eftposRef$current = eftposRef.current) === null || _eftposRef$current === void 0 || (_eftposRef$current$op = _eftposRef$current.open) === null || _eftposRef$current$op === void 0 || _eftposRef$current$op.call(_eftposRef$current, _objectSpread(_objectSpread({}, otherParams), {}, {
        payCallback: function payCallback(res) {
          return _eftpcallback(res, callback);
        }
      }));
    } else if (type === 'mx51') {
      var _mx51Ref$current, _mx51Ref$current$open;
      (_mx51Ref$current = mx51Ref.current) === null || _mx51Ref$current === void 0 || (_mx51Ref$current$open = _mx51Ref$current.open) === null || _mx51Ref$current$open === void 0 || _mx51Ref$current$open.call(_mx51Ref$current, _objectSpread(_objectSpread({}, otherParams), {}, {
        payCallback: function payCallback(res) {
          return _mx51callback(res, callback);
        }
      }));
    }
  };
  var _eftpcallback = function _eftpcallback(res, callback) {
    var params = {
      status: res.status,
      data: res.params
    };
    logger === null || logger === void 0 || logger.addLog({
      type: 'info',
      title: 'ToB_PaymentMethods_eftpos_callback',
      metadata: {
        res: res,
        params: params
      }
    });
    callback(params);
  };
  var _mx51callback = function _mx51callback(res, callback) {
    var params = {
      status: res.result ? 'success' : 'fail',
      data: {
        amount: res.amount,
        surcharge: res.surcharge,
        uniquePaymentNumber: res.nativeTxId || res.uniquePaymentNumber,
        action: res.action
      },
      msg: res.msg
    };
    logger === null || logger === void 0 || logger.addLog({
      type: 'info',
      title: 'ToB_PaymentMethods_mx51_callback',
      metadata: {
        res: res,
        params: params
      }
    });
    callback(params);
  };
  useImperativeHandle(ref, function () {
    return {
      onPay: onPay
    };
  });
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EFTPOS, {
    ref: eftposRef,
    dynamicMaxHeight: props === null || props === void 0 ? void 0 : props.dynamicMaxHeight,
    isWebPos: props === null || props === void 0 ? void 0 : props.isWebPos
  }), /*#__PURE__*/React.createElement(MX51, {
    ref: mx51Ref
  }));
};
export default /*#__PURE__*/forwardRef(PaymentMethods);