function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
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; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/**
 * 返回值0标识一样大，1表示v1大，-1表示v2大
 * @param v1
 * @param v2
 */
export function compareVersion(v1, v2) {
  if (!v1 && !v2) {
    return 0;
  } else if (!v1) {
    return -1;
  } else if (!v2) {
    return 1;
  }
  if (v1 === v2) {
    return 0;
  }
  if (!v1) {
    return -1;
  }
  if (!v2) {
    return 1;
  }

  // 1.6
  var vs1 = v1.split('.').map(function (a) {
    return parseInt(a);
  });
  // 1.6.1
  var vs2 = v2.split('.').map(function (a) {
    return parseInt(a);
  });
  var length = Math.min(vs1.length, vs2.length);
  for (var i = 0; i < length; i++) {
    if (vs1[i] > vs2[i]) {
      return 1;
    } else if (vs1[i] < vs2[i]) {
      return -1;
    }
  }
  if (length === vs1.length) {
    return -1;
  } else {
    return 1;
  }
}
/**
 * 判断version版本是否在range参数版本的范围内
 * @param version 
 * @param range 
 * @returns 
 */
export function isVersionInStringRange(version, range) {
  if (!range) {
    // 未指定版本限制
    return true;
  }
  if (range.includes(',')) {
    return range.split(',').includes(version);
  }
  if (!range.includes('|')) {
    return version === range;
  }
  var minVersion = range.split('|')[0];
  var maxVersion = range.split('|')[1] || '999999.9.9';
  var matchVersion = compareVersion(version, minVersion) >= 0 && compareVersion(maxVersion, version) >= 0;
  return matchVersion;
}
export function isVersionInRange(currentVersion, minVersion, maxVersion) {
  function splitVersion(version) {
    return version.split('.').map(function (num) {
      return parseInt(num, 10);
    });
  }
  function compareVersions(v1, v2) {
    for (var i = 0; i < Math.max(v1.length, v2.length); i++) {
      var num1 = v1[i] === undefined ? 0 : v1[i];
      var num2 = v2[i] === undefined ? 0 : v2[i];
      if (num1 > num2) return 1;
      if (num1 < num2) return -1;
    }
    return 0;
  }
  var current = splitVersion(currentVersion);
  var min = minVersion ? splitVersion(minVersion) : null;
  var max = maxVersion ? splitVersion(maxVersion) : null;
  if (min && compareVersions(current, min) < 0) {
    // 当前版本小于最小允许版本
    return false;
  }
  if (max && compareVersions(current, max) > 0) {
    // 当前版本大于最大允许版本
    return false;
  }
  // 当前版本在允许的版本范围内
  return true;
}
export function matchVersion(config, currentVersion) {
  var value = config.value,
    version = config.version,
    platform = config.platform;
  var CURRENT_PLATFORM = 'WEB';
  var isMatchVersion = false;
  var isMatchPlatform = false;

  // 平台判断
  if (platform) {
    var platformList = platform.split('|').map(function (platform) {
      return platform.toLocaleUpperCase();
    });
    isMatchPlatform = platformList.includes(CURRENT_PLATFORM);
  } else {
    // 没有表示平台全匹配
    isMatchPlatform = true;
  }
  // 版本判断
  if (!version) {
    // 为空全匹配
    isMatchVersion = true;
  } else if (version.indexOf('|') !== -1) {
    // | 范围匹配
    var _version$split = version.split('|'),
      _version$split2 = _slicedToArray(_version$split, 2),
      _version$split2$ = _version$split2[0],
      minVersion = _version$split2$ === void 0 ? '' : _version$split2$,
      _version$split2$2 = _version$split2[1],
      maxVersion = _version$split2$2 === void 0 ? '' : _version$split2$2;
    isMatchVersion = isVersionInRange(currentVersion, minVersion, maxVersion);
  } else if (version.indexOf(',') !== -1) {
    // , 枚举匹配
    var versionList = version.split(',');
    isMatchVersion = versionList.includes(currentVersion);
  } else {
    isMatchVersion = version === currentVersion;
  }
  return value && isMatchPlatform && isMatchVersion;
}