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); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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); }
/**
 * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
 * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
 */
/* eslint-disable @typescript-eslint/no-explicit-any */

var getType = function getType(target) {
  return Object.prototype.toString.call(target).slice(8, -1).toLowerCase();
};
var EventCenter = /*#__PURE__*/function () {
  function EventCenter() {
    _classCallCheck(this, EventCenter);
    _defineProperty(this, "events", void 0);
    _defineProperty(this, "eventsKey", void 0);
    this.events = new Map();
    this.eventsKey = new Map();
  }
  _createClass(EventCenter, [{
    key: "on",
    value: function on(name, func) {
      var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
      if (key) {
        if (this.eventsKey.has("".concat(name, "-").concat(key))) {
          // eslint-disable-next-line no-console
          console.warn("".concat(key, "\uFF1AHas been registered. Please use another key or do not pass the key"));
          return;
        }
        this.eventsKey.set("".concat(name, "-").concat(key), true);
      }
      var eventList = this.events.get(name) || [];
      eventList.push({
        func: func,
        key: key || ''
      });
      this.events.set(name, eventList);
    }
  }, {
    key: "off",
    value: function off(name, func) {
      var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
      if (key && this.eventsKey.has("".concat(name, "-").concat(key))) {
        this.eventsKey.delete("".concat(name, "-").concat(key));
      }
      if (this.events.has(name)) {
        var eventList = this.events.get(name);
        eventList = eventList.filter(function (item) {
          if (func === item.func && item.key === key) return false;
          if (item.key && item.key === key) return false;
          return true;
        });
        this.events.set(name, eventList);
      }
    }
  }, {
    key: "emit",
    value: function emit(name) {
      for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
        rest[_key - 1] = arguments[_key];
      }
      if (this.events.has(name)) {
        var eventList = this.events.get(name);
        eventList.forEach(function (item) {
          item.func.apply(item, rest);
        });
      }
    }
  }, {
    key: "once",
    value: function once(name, func, key) {
      var _this = this;
      var onceF = function onceF() {
        func.apply(void 0, arguments);
        _this.off(name, onceF, key);
      };
      this.on(name, onceF, key);
    }
  }, {
    key: "isExist",
    value: function isExist(name) {
      return this.events.has(name);
    }
  }]);
  return EventCenter;
}(); // TODO 直接访问 meta.viewPort 可能不正确，标准的meta viewport应该通过name属性查找
var getViewPort = function getViewPort(key) {
  var meta = document.getElementsByTagName('meta');
  // HTMLMetaElement
  var viewPort = meta.viewPort;
  var _meta = {};
  if (viewPort) {
    var content = viewPort.content.split(',');
    for (var j = 0; j < content.length; j++) {
      var i = content[j].split('=');
      _meta[i[0]] = i[1];
    }
  }
  return _meta[key];
};
var getOrigin = function getOrigin() {
  var _window$location = window.location,
    origin = _window$location.origin,
    protocol = _window$location.protocol,
    hostname = _window$location.hostname,
    port = _window$location.port;
  return origin || "".concat(protocol, "//").concat(hostname).concat(port ? ":".concat(port) : '');
};
var serialize = /* istanbul ignore next */function serialize(obj) {
  var s = [];
  for (var item in obj) {
    // eslint-disable-next-line no-prototype-builtins
    if (obj.hasOwnProperty(item)) {
      var k = encodeURIComponent(item);
      var v = encodeURIComponent(obj[item] === null ? '' : obj[item]);
      s.push("".concat(k, "=").concat(v));
    }
  }
  return s.join('&');
};
var isJsonString = function isJsonString(str) {
  try {
    JSON.parse(str);
  } catch (e) {
    return false;
  }
  return true;
};
var isDom = function isDom(obj) {
  if ((typeof HTMLElement === "undefined" ? "undefined" : _typeof(HTMLElement)) === 'object') {
    return obj instanceof HTMLElement;
  } else {
    return obj && _typeof(obj) === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';
  }
};
var _window = window,
  navigator = _window.navigator;
var UA = navigator.userAgent;
var isIOS = /iPhone|iPad|iPod/i.test(UA) || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
var isAndroid = /Android/i.test(UA);
var isMacOS = /\bMacintosh\b/.test(UA);
var isWindowsNT = /Windows NT/.test(UA);
var isMobile = function isMobile() {
  return /Android|iPhone|iPad|iPod|Mobile/.test(UA) || isOpenHarmonyMobile();
};
// TODO 未导出
var isOpenHarmony = function isOpenHarmony() {
  // 检查是否为鸿蒙操作系统
  return /OpenHarmony/i.test(navigator.userAgent);
};
var isOpenHarmonyMobile = function isOpenHarmonyMobile() {
  // 检查是否为鸿蒙操作系统
  var isHarmonyOS = /OpenHarmony/i.test(navigator.userAgent);
  // 检查是否为手机设备
  var isPhone = /Phone/i.test(navigator.userAgent);
  // 检查是否为平板设备
  var isTablet = /Tablet/i.test(navigator.userAgent);
  // 返回是否为鸿蒙手机或平板
  return isHarmonyOS && (isPhone || isTablet);
};
// TODO 未导出
var isOpenHarmonyPC = function isOpenHarmonyPC() {
  // 检查是否为鸿蒙操作系统
  return /OpenHarmony/i.test(navigator.userAgent) && /PC/i.test(navigator.userAgent);
};
var device = {
  iOS: isIOS,
  Android: isAndroid,
  macOS: isMacOS,
  WindowsNT: isWindowsNT,
  isMobile: !!isMobile(),
  isOpenHarmonyMobile: !!isOpenHarmonyMobile()
};
var safeJson = function safeJson(data, obj) {
  try {
    return JSON.parse(data) || obj;
  } catch (_unused) {
    return obj;
  }
};
var isPC = function isPC() {
  var userAgentInfo = navigator.userAgent;
  var agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPod'];
  return !agents.some(function (agent) {
    return userAgentInfo.includes(agent);
  });
};
var queryParse = function queryParse(url) {
  var qs = {};
  if (!url) {
    // eslint-disable-next-line no-param-reassign
    url = window.location.href;
  }
  url.replace(/([^?=&#]+)(=([^&#]*))?/g, function (_$0, $1, _$2, $3) {
    if ($3 === undefined) {
      return '';
    }
    qs[$1] = decodeURIComponent($3);
    return qs[$1];
  });
  return qs;
};
var designSize = 390;
var maxFontSize = 130;
var getDesignFontSize = function getDesignFontSize() {
  var screenWidth = document.documentElement.clientWidth;
  var currentFontSize = isPC() ? maxFontSize : screenWidth * 100 / designSize;
  return Math.min(currentFontSize, maxFontSize);
};
var amsSetSize = function amsSetSize(event, dom) {
  try {
    var componentContainerId = 'ams-component-container';
    var _dom = dom || document.getElementById(componentContainerId);
    _dom.style.fontSize = "".concat(getDesignFontSize(), "px");
    window.changingPageHeight = window.innerHeight;
    // eslint-disable-next-line no-empty
  } catch (error) {}
};
var addSetFontSizeEvent = function addSetFontSizeEvent() {
  window.removeEventListener('resize', amsSetSize);
  window.removeEventListener('pageShow', amsSetSize);
  window.removeEventListener('DOMContentLoaded', amsSetSize);
  window.addEventListener('resize', amsSetSize);
  window.addEventListener('pageShow', amsSetSize);
  window.addEventListener('DOMContentLoaded', amsSetSize);
};

/**
 * @description get or set STORAGE
 */
var getOrSetStorageId = function getOrSetStorageId(key, value) {
  try {
    if (key && !value) {
      var storageValue = window.localStorage.getItem(key);
      if (storageValue) {
        return storageValue;
      } else return '';
    }
    if (key && value) {
      window.localStorage.setItem(key, value);
    }
  } catch (error) {
    return '';
  }
};
var checkTimeElapsed = function checkTimeElapsed() {
  var key = 'antomSDKConfiglastCallTime';
  var currentTime = new Date().getTime();
  try {
    var lastCallTime = localStorage.getItem(key);
    if (lastCallTime) {
      var elapsedTime = currentTime - parseInt(lastCallTime);
      if (elapsedTime >= 10 * 60 * 1000) {
        // 记录当前调用时间
        localStorage.setItem(key, currentTime.toString());
        // 超过10分钟
        return true;
      }
      return false;
    }
  } catch (error) {
    /* empty */
  }
  // 记录当前调用时间
  localStorage.setItem(key, currentTime.toString());
  return true;
};
var isFunction = function isFunction(func) {
  return typeof func === 'function';
};
// https://developer.mozilla.org/en-US/docs/Glossary/Base64
function parseBase64ToString(base64) {
  try {
    var binString = atob(base64);
    var uint8Array = Uint8Array.from(binString, function (m) {
      return m.codePointAt(0);
    });
    return new TextDecoder().decode(uint8Array);
  } catch (error) {
    return null;
  }
}
function loadSDKScript(_ref, logger) {
  var _this2 = this;
  var src = _ref.src,
    _ref$attrOptions = _ref.attrOptions,
    attrOptions = _ref$attrOptions === void 0 ? {} : _ref$attrOptions,
    _ref$timeOut = _ref.timeOut,
    timeOut = _ref$timeOut === void 0 ? 3 : _ref$timeOut,
    _ref$loadCallback = _ref.loadCallback,
    loadCallback = _ref$loadCallback === void 0 ? null : _ref$loadCallback;
  return new Promise(function (resolve, reject) {
    // 创建 script 标签
    logger.logInfo({
      title: 'load_item_sdk_start'
    }, {
      eventMessage: src
    });
    console.time();
    var script = document.createElement('script');
    var timer = null;
    script.type = 'text/javascript';

    // 监听加载完成事件
    script.onload = function () {
      // 当脚本加载完毕时，执行回调函数
      logger.logInfo({
        title: 'load_item_sdk_end'
      }, {
        eventMessage: src
      });
      console.timeEnd();
      clearTimeout(timer);
      if (loadCallback) loadCallback();
      resolve(true);
    };

    // 监听加载失败事件
    script.onerror = function () {
      logger.logError({
        title: 'load_item_sdk_error'
      }, {
        eventMessage: src
      });
      clearTimeout(timer);
      console.error('The script ' + src + ' is not accessible.');
      reject(false);
    };
    timer = setTimeout(function () {
      // TODO 直接使用 logger 参数，而不是 this.logger
      _this2.logger.logError({
        title: 'load_item_sdk_timeout'
      }, {
        eventMessage: src
      });
      reject(false);
    }, timeOut * 1000);
    script.src = src;
    attrOptions && Object.keys(attrOptions).forEach(function (key) {
      script.setAttribute(key, attrOptions[key]);
    });
    // 将 script 标签添加到页面中
    document.head.appendChild(script);
  });
}
var isEmpty = function isEmpty(value) {
  // 判断空对象
  if (value && _typeof(value) === 'object' && Object.keys(value).length === 0) {
    return true;
  }
  // 判断空数组
  if (Array.isArray(value) && value.length === 0) {
    return true;
  }
  // 判断空值
  if (value === null || value === undefined || value === '') {
    return true;
  }
  return false;
};

/**
 * 判断一个值是否为真
 * @param value 要判断的值
 * @returns 如果值为true或者字符串"true"（不区分大小写），则返回true，否则返回false
 */
var isTrue = function isTrue(value) {
  return value === true || typeof value === 'string' && value.toLowerCase() === 'true';
};
export var omit = function omit(obj, keys) {
  return Object.keys(obj).reduce(function (acc, key) {
    if (!keys.includes(key)) {
      acc[key] = obj[key];
    }
    return acc;
  }, {});
};
export { getType, EventCenter, getViewPort, getOrigin, serialize, isJsonString, isDom, isFunction, device, safeJson, isPC, queryParse, getDesignFontSize, amsSetSize, addSetFontSizeEvent, getOrSetStorageId, checkTimeElapsed, parseBase64ToString, loadSDKScript, isEmpty, isTrue };