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: 初始化 windcave 数据
 * @return store 全局数据管理
 * @Author: hongbing.wang
 * @Date: 2024-08-12 10:42
 */
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({
    order_id: order_id,
    name: name,
    symbol: symbol,
    amount: amount,
    mode: mode,
    eftpos: EftposEnum.Windcave,
    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 ? _objectSpread(_objectSpread({}, other), {}, {
      list: [],
      step: StepStatusEnum.Free
    }) : {
      list: [],
      step: StepStatusEnum.Free
    }
  }, typeof net !== 'undefined' ? {
    net: net
  } : {}), typeof number !== 'undefined' ? {
    number: number
  } : {}), typeof pay !== 'undefined' ? {
    pay: pay
  } : {}), typeof device !== 'undefined' ? {
    device: device
  } : {});
});

/**
 * @title:  windcave 金额信息
 * @description:
 * @param {State} store : 全局store数据管理
 * @return 金额信息
 * @Author: hongbing.wang
 * @Date: 2024-08-12 10:43
 */
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,
      // format,
      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,
      // format,
      money: Number(amount),
      amount: Number(amount),
      surRate: 0,
      surMoney: 0,
      surcharge: false,
      useOriginSurcharge: false
    };
  }
  var 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
  };
}
export var StepStatusEnum = /*#__PURE__*/function (StepStatusEnum) {
  StepStatusEnum[StepStatusEnum["Free"] = 1] = "Free";
  StepStatusEnum[StepStatusEnum["Card"] = 2] = "Card";
  StepStatusEnum[StepStatusEnum["Account"] = 3] = "Account";
  StepStatusEnum[StepStatusEnum["Application"] = 4] = "Application";
  StepStatusEnum[StepStatusEnum["Pin"] = 5] = "Pin";
  StepStatusEnum[StepStatusEnum["Processing"] = 6] = "Processing";
  StepStatusEnum[StepStatusEnum["Receipt"] = 7] = "Receipt";
  StepStatusEnum[StepStatusEnum["Wait"] = 8] = "Wait";
  return StepStatusEnum;
}({});
export var StemTypeEnum = /*#__PURE__*/function (StemTypeEnum) {
  StemTypeEnum["Active"] = "active";
  StemTypeEnum["Passive"] = "passive";
  return StemTypeEnum;
}({});

/**
 * @title: windcave 步骤信息
 * @description: 步骤对应配置信息
 * @return 步骤配置信息
 * @Author: hongbing.wang
 * @Date: 2024-08-12 10:44
 */
export var getStepMapping = function getStepMapping(type, _ref2) {
  var money = _ref2.money,
    _ref2$mode = _ref2.mode,
    mode = _ref2$mode === void 0 ? ModeEnum.Pay : _ref2$mode;
  switch (type) {
    case StepStatusEnum.Free:
      return {
        type: StemTypeEnum.Active,
        // passive  active
        status: 'pedding',
        // pedding reject resolve
        pedding: locales.getText('page.eftpos-pay.text.wait')(money || '', mode),
        resolve: '',
        index: type,
        peddingStyle: {}
      };
    case StepStatusEnum.Card:
      return {
        type: StemTypeEnum.Active,
        // passive  active
        status: 'pedding',
        // pedding reject resolve
        pedding: locales.getText('page.eftpos-pay.text.card'),
        resolve: '',
        index: type,
        peddingStyle: {}
      };
    case StepStatusEnum.Account:
      return {
        type: StemTypeEnum.Active,
        // passive  active
        status: 'pedding',
        // pedding reject resolve
        pedding: locales.getText('page.eftpos-pay.text.account'),
        resolve: '',
        index: type,
        peddingStyle: {}
      };
    case StepStatusEnum.Application:
      return {
        type: StemTypeEnum.Active,
        // passive  active
        status: 'pedding',
        // pedding reject resolve
        pedding: locales.getText('page.eftpos-pay.text.application'),
        // '等待客户选择应用', // Waiting for customer to select application/等待客户选择应用
        resolve: '',
        index: type,
        peddingStyle: {}
      };
    case StepStatusEnum.Pin:
      return {
        type: StemTypeEnum.Active,
        // passive  active
        status: 'pedding',
        // pedding reject resolve
        pedding: locales.getText('page.eftpos-pay.text.pin'),
        resolve: '',
        index: type,
        peddingStyle: {}
      };
    case StepStatusEnum.Processing:
      return {
        type: StemTypeEnum.Active,
        // passive  active
        status: 'pedding',
        // pedding reject resolve
        pedding: locales.getText('page.eftpos-pay.text.transaction.processing'),
        // Processing/处理中
        resolve: '',
        index: type,
        peddingStyle: {}
      };
    case StepStatusEnum.Receipt:
      return {
        type: StemTypeEnum.Passive,
        // passive  active
        status: 'pedding',
        //
        pedding: "".concat(locales.getText('page.eftpos-pay.text.receipt.again.title'), "\n").concat(locales.getText('page.eftpos-pay.text.receipt.again.text')),
        // pedding:  (
        //   <>
        //     {locales.getText('page.eftpos-pay.text.receipt.again.title')}
        //     <br />
        //     {locales.getText('page.eftpos-pay.text.receipt.again.text')}
        //   </>
        // ),
        resolve: locales.getText('page.eftpos-pay.text.receipt.again.title'),
        reject: locales.getText('page.eftpos-pay.text.receipt.again.title'),
        // locales.getText('page.eftpos-pay.text.waiting.decline'), // 'Wait for the Decline',
        index: type,
        peddingStyle: {}
      };
    case StepStatusEnum.Wait:
      return {
        type: StemTypeEnum.Active,
        // passive  active
        status: 'pedding',
        // pedding reject resolve
        pedding: locales.getText('page.eftpos-pay.text.waiting.processing'),
        resolve: locales.getText('page.eftpos-pay.text.approved'),
        index: type,
        peddingStyle: {}
      };
    default:
      // throw Error('');
      return null;
  }
};