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 = ["order_id", "name", "symbol", "amount", "mode", "number", "pay", "device", "net", "client"];
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 { locales } from '@pisell/utils';
import { EftposEnum, StatusEnum, PayRouteEnum, ModeEnum, ClientEnum } from "../const";
/**
 * @title: 初始化 tyro 数据
 * @Author: hongbing.wang
 * @Date: 2024-08-20 13:50
 */
export default (function (params) {
  var _ref = params || {
      mode: ModeEnum.Pay
    },
    order_id = _ref.order_id,
    name = _ref.name,
    symbol = _ref.symbol,
    amount = _ref.amount,
    mode = _ref.mode,
    number = _ref.number,
    pay = _ref.pay,
    device = _ref.device,
    net = _ref.net,
    client = _ref.client,
    other = _objectWithoutProperties(_ref, _excluded);
  return _objectSpread(_objectSpread(_objectSpread(_objectSpread({
    name: name,
    symbol: symbol,
    amount: amount,
    order_id: order_id,
    mode: mode,
    eftpos: EftposEnum.Tyro,
    key: Date.now(),
    warn: '',
    step: 0,
    type: PayRouteEnum.Step,
    title: locales.getText('page.eftpos-pay.text.loading')(mode),
    component: '',
    status: StatusEnum.Loading,
    steps: [],
    render: true,
    client: client !== 'undefined' && client !== undefined ? client : ClientEnum.Merchant,
    custom: other || {}
  }, typeof net !== 'undefined' ? {
    net: net
  } : {}), typeof number !== 'undefined' ? {
    number: number
  } : {}), typeof pay !== 'undefined' ? {
    pay: pay
  } : {}), typeof device !== 'undefined' ? {
    device: device
  } : {});
});

/**
 * @title:  tyro 金额信息
 * @description: 在 amount 页面设置则使用 pay ,如果有 setting 则使用 setting 信息 ,都没有则设置0
 * @param {State} store : 全局store数据管理
 * @Author: hongbing.wang
 * @Date: 2024-08-12 10:24
 */
export function getAmonunt(store) {
  var device = store.device,
    pay = store.pay,
    custom = store.custom,
    name = store.name,
    symbol = store.symbol,
    amount = store.amount;
  if (!device || !custom) {
    throw Error('device or custom is not defined');
  }
  var setting = device.setting;

  // 从 金额编辑页 获取到 支付数据
  if (pay) {
    return {
      name: name,
      symbol: symbol,
      money: Number(amount),
      amount: Number(pay.amount),
      surRate: Number(pay.surRate),
      surMoney: Number(pay.surMoney),
      surcharge: (setting === null || setting === void 0 ? void 0 : setting.surcharge) || false,
      useOriginSurcharge: (pay === null || pay === void 0 ? void 0 : pay.useOriginSurcharge) || false
    };
  }

  // 直接获取支付金额
  if (!setting) {
    return {
      name: name,
      symbol: symbol,
      money: Number(amount),
      amount: Number(amount),
      surRate: 0,
      surMoney: 0,
      surcharge: false,
      useOriginSurcharge: false
    };
  }
  var useOriginSurcharge = setting.useOriginSurcharge || false;

  // 直接设备中手续费金额

  var surRate = setting.constant_rate || 0;
  var surMoney = setting.constant_money || 0;
  var surcharge = setting.surcharge;
  return {
    name: name,
    symbol: symbol,
    money: Number(amount),
    amount: Number(amount),
    surRate: useOriginSurcharge ? 0 : surcharge ? surRate : 0,
    surMoney: useOriginSurcharge ? 0 : surcharge ? surMoney : 0,
    surcharge: surcharge,
    useOriginSurcharge: useOriginSurcharge
  };
}