import _typeof from "@babel/runtime/helpers/esm/typeof";

/**
 * o2o.js
 *
 * @Author: apple
 * @Date: 2018/2/5 22:59
 */
import { isNull, isUndefined, isNumber, isBoolean } from './isType'; // 去重

Array.prototype.unique = function () {
  this.sort();
  var re = [this[0]];

  for (var i = 1; i < this.length; i++) {
    if (this[i] !== re[re.length - 1]) {
      re.push(this[i]);
    }
  }

  return re;
};

var isValidData = function isValidData(a, b) {
  if (_typeof(a) !== _typeof(b)) {
    return false;
  }

  if (isNull(a) || isUndefined(a) || isNumber(a) || isBoolean(a)) {
    return false;
  }

  if (_typeof(a.length) !== _typeof(b.length)) {
    return false;
  }

  if (a.length !== b.length) {
    return false;
  }

  return true;
};

export var isEqualArrays = function isEqualArrays(a1, a2) {
  var bool;

  if (!isValidData(a1, a2)) {
    return false;
  }

  bool = a1.some(function (e, i) {
    return e !== a2[i];
  });
  return !bool;
};
export var o2o = function o2o(o1, o2, debug) {
  if (_typeof(o1) !== _typeof(o2)) {
    return false;
  }

  if (isNull(o1) || isUndefined(o1) || isNumber(o1) || isBoolean(o1)) {
    return false;
  }

  if (_typeof(o1.length) !== _typeof(o2.length)) {
    return false;
  }

  var bool = true;
  var keyArr1 = [];
  var keyArr2 = [];

  for (var i in o1) {
    keyArr1.push(i);
  }

  for (var _i in o2) {
    keyArr2.push(_i);
  }

  if (keyArr1.length != keyArr2.length) {
    return false;
  }

  for (var _i2 = 0, k = keyArr2.length; _i2 < k; _i2++) {
    keyArr1.push(keyArr2[_i2]);
  }

  var keyArr = keyArr1.unique();

  for (var _i3 = 0, _k = keyArr.length; _i3 < _k; _i3++) {
    if (keyArr[_i3] in o1 && keyArr[_i3] in o2) {
      if (_typeof(o1[keyArr[_i3]]) === 'object' && _typeof(o2[keyArr[_i3]]) === 'object') {
        bool = o2o(o1[keyArr[_i3]], o2[keyArr[_i3]]);
      } else if (o1[keyArr[_i3]] !== o2[keyArr[_i3]]) {
        return false;
      }
    } else {
      return false;
    }
  }

  return bool;
};
export default o2o;