function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
// Device
var Device = function () {
  var userAgent = navigator.userAgent;
  var ua = userAgent.toLowerCase();
  // 内核
  var kernel = '';
  if (ua.indexOf('trident') > -1) {
    kernel = 'trident';
  } else if (ua.indexOf('presto') > -1) {
    kernel = 'presto';
  } else if (ua.indexOf('applewebkit') > -1) {
    kernel = 'webkit';
  } else if (ua.indexOf('gecko') > -1 && ua.indexOf('khtml') === -1) {
    kernel = 'gecko';
  }
  // 设备
  var device = '';
  if (ua.match(/applewebkit.*mobile.*/)) {
    device = 'mobile';
  } else {
    device = 'pc';
  }
  // 系统
  var os = '';
  var osVersion = '';
  var androidExp = ua.match(/android\s*(\d*\.*\d*)/);
  var iosExp = ua.match(/cpu iphone os (.*?) like mac os/);
  var harmonyExp = ua.match(/openharmony\s*(\d*\.*\d*)/);
  if (androidExp) {
    os = 'android';
    osVersion = androidExp[1];
  } else if (iosExp) {
    os = 'ios';
    osVersion = iosExp[1];
  } else if (harmonyExp) {
    os = 'harmony';
    osVersion = harmonyExp[1];
  }

  // 平台
  var platform = '';
  var platformVersion = '';
  var platformMatch = null;
  function updatePlatform() {
    // 微信小程序
    if (ua.indexOf('miniprogram') > -1 && ua.indexOf('micromessenger') > -1) {
      if (ua.indexOf('wxwork') > -1) {
        platform = 'weworkMiniprogram';
        platformMatch = ua.match(/wxwork\/([\w.]*)/);
      } else if (ua.indexOf('micromessenger') > -1) {
        platform = 'wechatMiniprogram';
        platformMatch = ua.match(/micromessenger\/([\w.]*)/);
      }
      if (platformMatch && platformMatch[1]) platformVersion = platformMatch[1];
    }
    // 企业微信
    else if (ua.indexOf('wxwork') > -1) {
      platform = 'wework';
      platformMatch = ua.match(/wxwork\/([\w.]*)/);
      if (platformMatch && platformMatch[1]) platformVersion = platformMatch[1];
    }
    // 微信
    else if (ua.indexOf('micromessenger') > -1) {
      platform = 'wechat';
      platformMatch = ua.match(/micromessenger\/([\w.]*)/);
      if (platformMatch && platformMatch[1]) platformVersion = platformMatch[1];
    }
    // 支付宝
    else if (ua.indexOf('alipay') > -1) {
      platform = 'alipay';
      if (ua.indexOf('miniprogram') > -1) {
        platform = 'alipayMiniprogram';
      }
      platformMatch = ua.match(/alipayclient\/([\w.]*)/);
      if (platformMatch && platformMatch[1]) platformVersion = platformMatch[1];
    }
    // 钉钉
    else if (ua.indexOf('dingtalk') > -1) {
      platform = 'dingtalk';
      platformMatch = ua.match(/dingtalk\/([\w.]*)/);
      if (platformMatch && platformMatch[1]) platformVersion = platformMatch[1];
    }
    // 飞书
    else if (ua.indexOf('lark') > -1) {
      platform = 'lark';
      platformMatch = ua.match(/lark\/([\w.]*)/);
      if (platformMatch && platformMatch[1]) platformVersion = platformMatch[1];
    }
    // QQ
    else if (ua.indexOf('mqqbrowser') > -1) {
      platform = 'qq';
    }
    // UC
    else if (ua.indexOf('ucbrowser') > -1) {
      platform = 'uc';
    }
    // 其它浏览器
    else {
      platform = 'browser';
      var _platformMatch = ua.match(/version\/([\d.]+)/);
      platformVersion = (_platformMatch === null || _platformMatch === void 0 ? void 0 : _platformMatch[1]) || '';
    }
  }
  updatePlatform();

  // 以下两个方法都不准备
  // 获得苹果机型
  function appleModel() {
    // 获取设备型号
    if (ua && /(iphone|ipad|ipod|ios)/i.test(ua)) {
      var m = ua.match(/mobile\/([\w.]*)/);
      if (m && m[1]) {
        return m[1];
      }
    }
    return '';
  }
  // 获取苹果设备名称
  function getAppleDevice() {
    // iPhoneX | iPhoneXS
    if (/iphone/gi.test(ua) && window.screen.height === 812 && window.screen.width === 375) return 'iPhoneX';
    // iPhoneXSM | iPhoneXSR
    if (/iphone/gi.test(ua) && window.screen.height === 896 && window.screen.width === 414) return 'iPhoneXSM';
    var model = appleModel();
    switch (model) {
      case '15b150':
        return 'iPhone6s';
      case '15b202':
        return 'iPhone6';
      case '13g36':
        return 'iPhone5SE';
      case '14e304':
        return 'iPhone6P';
      default:
        return '';
    }
  }

  // 网络监听
  var onLineCallback;
  function handleOnline(e) {
    onLineCallback(true);
  }
  function handleOffline(e) {
    onLineCallback(false);
  }
  function onLine(callback) {
    onLineCallback = callback;
    window.removeEventListener('online', handleOnline, false);
    window.removeEventListener('offline', handleOffline, false);
    window.addEventListener('online', handleOnline, false);
    window.addEventListener('offline', handleOffline, false);
  }

  // 获取地址栏参数
  function getUrlParameter(argName, argSearch) {
    var _url, _url$indexOf;
    var url = window.location.href;
    if (argSearch) url = argSearch;
    var params = {};
    // 如果url中包含?说明有参数
    if (((_url = url) === null || _url === void 0 || (_url$indexOf = _url.indexOf) === null || _url$indexOf === void 0 ? void 0 : _url$indexOf.call(_url, '?')) !== -1) {
      var _url$split$;
      if (!argName) return '?' + url.split('?')[1];
      // 获取所有参数options: 如?a=1&b=2转为['a=1','b=2']
      var options = (_url$split$ = url.split('?')[1]) === null || _url$split$ === void 0 ? void 0 : _url$split$.split('&');
      if (options !== null && options !== void 0 && options.length) {
        for (var i = 0; i < options.length; i++) {
          // 获取单项option: 如'a=1'转为['a', '1']
          var option = options[i].split('=');
          if (option.length === 2) {
            if (argName) {
              if (argName === option[0]) return option[1];
            } else {
              params[option[0]] = option[1];
            }
          }
        }
      }
    }
    if (Object.keys(params).length) return params;
    return '';
  }
  // 获取屏幕宽高
  function getScreenWidth() {
    if (window.innerWidth) return window.innerWidth;
    if (window.screen.width) return window.screen.width;
    if (window.screen.availWidth) return window.screen.availWidth;
  }
  function getScreenHeight() {
    if (window.innerHeight) return window.innerHeight;
    if (window.screen.height) return window.screen.height;
    if (window.screen.availHeight) return window.screen.availHeight;
  }
  // 获取手机型号(ios返回版本号, 因为ios取不到型号)
  function getModel() {
    var model = '';
    if (userAgent.toLowerCase().match(/android\s*(\d*\.*\d*)/)) {
      var infos = userAgent.split(';');
      var _iterator = _createForOfIteratorHelper(infos),
        _step;
      try {
        for (_iterator.s(); !(_step = _iterator.n()).done;) {
          var info = _step.value;
          if (info.indexOf('Build') !== -1) {
            info = info.trim();
            model = info.substring(0, info.indexOf(' Build'));
            break;
          }
        }
      } catch (err) {
        _iterator.e(err);
      } finally {
        _iterator.f();
      }
      if (!model) model = '';
    } else {
      var iosVersion = '';
      var _iosExp = userAgent.toLowerCase().match(/cpu iphone os (.*?) like mac os/);
      if (_iosExp && _iosExp[1]) {
        iosVersion = _iosExp[1].replace(/_/gim, '.');
      }
      model = "iPhone ".concat(iosVersion);
    }
    return model;
  }
  return {
    /**
     * @deprecated since version 5.2.8
     * 请勿使用此属性
     */
    appleDevice: getAppleDevice(),
    /**
     * @deprecated since version 5.2.8
     * 请勿使用此属性
     */
    appVersion: window.navigator.appVersion,
    /**
     * @deprecated since version 5.2.8
     * 请勿使用此属性
     */
    onLine: onLine,
    /**
     * @deprecated since version 5.2.8
     * 请勿使用此属性
     */
    ua: ua,
    // 应用程序判断
    language: (window.navigator.browserLanguage || window.navigator.language).toLowerCase(),
    protocol: window.location.protocol,
    host: window.location.host,
    domain: window.location.protocol + '//' + window.location.host,
    kernel: kernel,
    device: device,
    os: os,
    osVersion: osVersion,
    model: getModel(),
    platform: platform,
    platformVersion: platformVersion,
    isOnLine: window.navigator.onLine || true,
    userAgent: ua,
    getUrlParameter: getUrlParameter,
    screenWidth: getScreenWidth(),
    screenHeight: getScreenHeight(),
    // 比较版本号, -1小于 0等于 1大于
    compareVersion: function compareVersion(v1, v2) {
      var separator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '.';
      // Comaptiable with IOS version
      if (v1.indexOf(separator) === -1 && v1.indexOf('_') !== -1) {
        // eslint-disable-next-line
        v1 = v1.replace(/_/gim, separator);
      }
      if (v2.indexOf(separator) === -1 && v2.indexOf('_') !== -1) {
        // eslint-disable-next-line
        v2 = v2.replace(/_/gim, separator);
      }
      var v1Parts = v1.split(separator).map(Number);
      var v2Parts = v2.split(separator).map(Number);
      var length = Math.max(v1Parts.length, v2Parts.length);
      for (var i = 0; i < length; i++) {
        var part1 = v1Parts[i] || 0; // 如果没有该部分，默认为0
        var part2 = v2Parts[i] || 0; // 如果没有该部分，默认为0

        if (part1 < part2) return -1;
        if (part1 > part2) return 1;
      }
      return 0; // 如果所有部分都相等
    }
  };
}();
export default Device;