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); }
/**
 * 在window对象上记录商户初始化SDK的StartTime,加载结束时间
 * 后续传递给Web应用,用于进行端到端渲染总耗时计算
 * ***/

import { ProductSceneEnum } from "../../types";

/*** 扩展 Window 接口，添加 _ANTOM_SDK_PROXY_TIME 属性*/

/*** 往window对象上注入全局变量 _ANTOM_SDK_PROXY_TIME */
function injectAntomSDKProxyStartTime() {
  if (typeof window === 'undefined') {
    return;
  }
  if (_typeof(window._ANTOM_SDK_PROXY_TIME) !== 'object') {
    window._ANTOM_SDK_PROXY_TIME = {};
  }
  return window._ANTOM_SDK_PROXY_TIME;
}
export function setProxyStartTime(constructorName, startTime) {
  injectAntomSDKProxyStartTime();
  if (_typeof(window._ANTOM_SDK_PROXY_TIME) !== 'object') return startTime;
  var timeObject = window._ANTOM_SDK_PROXY_TIME[constructorName];
  if (_typeof(timeObject) !== 'object') {
    window._ANTOM_SDK_PROXY_TIME[constructorName] = {
      startTime: startTime,
      endTime: 0
    };
  } else {
    timeObject.startTime = startTime;
  }
  return startTime;
}
export function setProxyEndTime(constructorName, endTime) {
  if (_typeof(window._ANTOM_SDK_PROXY_TIME) !== 'object') return endTime;
  var timeObject = window._ANTOM_SDK_PROXY_TIME[constructorName];
  if (_typeof(timeObject) !== 'object') {
    window._ANTOM_SDK_PROXY_TIME[constructorName] = {
      startTime: 0,
      endTime: endTime
    };
  } else {
    timeObject.endTime = endTime;
  }
  return endTime;
}
export var getProxyCostTime = function getProxyCostTime(productScene) {
  var _window, _window2, _timeObj, _timeObj2;
  var timeObj;
  switch (productScene) {
    case ProductSceneEnum.ELEMENT_PAYMENT:
      timeObj = (_window = window) === null || _window === void 0 || (_window = _window._ANTOM_SDK_PROXY_TIME) === null || _window === void 0 ? void 0 : _window['AMSElement'];
      break;
    case ProductSceneEnum.EASY_PAY:
      timeObj = (_window2 = window) === null || _window2 === void 0 || (_window2 = _window2._ANTOM_SDK_PROXY_TIME) === null || _window2 === void 0 ? void 0 : _window2['AMSEasyPay'];
      break;
    default:
      timeObj = {
        startTime: 0,
        endTime: 0
      };
      break;
  }
  return ((_timeObj = timeObj) === null || _timeObj === void 0 ? void 0 : _timeObj.endTime) - ((_timeObj2 = timeObj) === null || _timeObj2 === void 0 ? void 0 : _timeObj2.startTime) || 0;
};