import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _typeof from "@babel/runtime/helpers/typeof";
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; }
export var getOpCardinality = function getOpCardinality(opDef) {
  var _opDef$cardinality;
  return (_opDef$cardinality = opDef === null || opDef === void 0 ? void 0 : opDef.cardinality) !== null && _opDef$cardinality !== void 0 ? _opDef$cardinality : 1;
};
export var truncateString = function truncateString(str, n, useWordBoundary) {
  if (!n || !str || str.length <= n) {
    return str;
  }
  var subString = str.substr(0, n - 1);
  return (useWordBoundary ? subString.substr(0, subString.lastIndexOf(" ")) : subString) + "...";
};
export var immutableEqual = function immutableEqual(v1, v2) {
  if (v1 === v2) {
    return true;
  } else {
    return v1 === null || v1 === void 0 ? void 0 : v1.equals(v2);
  }
};

// const deepEqual = function(v1, v2) {
//   if (v1 === v2) {
//     return true;
//   } else if (Map.isMap(v1)) {
//     return v1.equals(v2);
//   } else {
//     return JSON.stringify(v1) == JSON.stringify(v2);
//   }
// };

export var shallowEqual = function shallowEqual(a, b) {
  var deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  if (a === b) {
    return true;
  } else if (Array.isArray(a)) return shallowEqualArrays(a, b, deep);else if (a && typeof a.equals === "function") return a.equals(b);else if (_typeof(a) === "object") return shallowEqualObjects(a, b, deep);else return a === b;
};
function shallowEqualArrays(arrA, arrB) {
  var deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  if (arrA === arrB) {
    return true;
  }
  if (!arrA || !arrB) {
    return false;
  }
  var len = arrA.length;
  if (arrB.length !== len) {
    return false;
  }
  for (var i = 0; i < len; i++) {
    var isEqual = deep ? shallowEqual(arrA[i], arrB[i], deep) : arrA[i] === arrB[i];
    if (!isEqual) {
      return false;
    }
  }
  return true;
}
function shallowEqualObjects(objA, objB) {
  var deep = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  if (objA === objB) {
    return true;
  }
  if (!objA || !objB) {
    return false;
  }
  var aKeys = Object.keys(objA);
  var bKeys = Object.keys(objB);
  var len = aKeys.length;
  if (bKeys.length !== len) {
    return false;
  }
  for (var i = 0; i < len; i++) {
    var key = aKeys[i];
    var isEqual = deep ? shallowEqual(objA[key], objB[key], deep) : objA[key] === objB[key];
    if (!isEqual) {
      return false;
    }
  }
  return true;
}
var isDev = function isDev() {
  var _process;
  return typeof process !== "undefined" && ((_process = process) === null || _process === void 0 || (_process = _process.env) === null || _process === void 0 ? void 0 : _process.NODE_ENV) == "development";
};
var isTest = function isTest() {
  var _process2;
  return typeof process !== "undefined" && ((_process2 = process) === null || _process2 === void 0 || (_process2 = _process2.env) === null || _process2 === void 0 ? void 0 : _process2.NODE_ENV_TEST) == "true";
};
export var getLogger = function getLogger(devMode) {
  if (isTest()) {
    return _objectSpread(_objectSpread({}, console), {}, {
      log: function log() {},
      debug: function debug() {},
      info: function info() {}
    });
  }
  var verbose = devMode != undefined ? devMode : isDev();
  return verbose ? console : {
    error: function error() {},
    log: function log() {},
    warn: function warn() {},
    debug: function debug() {},
    info: function info() {}
  };
};
export var logger = getLogger();