import equal from "../../../../@gilbarbara_deep-equal@0.1.2/node_modules/@gilbarbara/deep-equal/esm/index.js";
import is from "../../../../is-lite@0.8.2/node_modules/is-lite/esm/index.js";
function canHaveLength() {
  var arguments_ = [];
  for (var _i = 0; _i < arguments.length; _i++) {
    arguments_[_i] = arguments[_i];
  }
  return arguments_.every(function(d) {
    return is.string(d) || is.array(d) || is.plainObject(d);
  });
}
function checkEquality(left, right, value) {
  if (!isSameType(left, right)) {
    return false;
  }
  if ([left, right].every(is.array)) {
    return !left.some(hasValue(value)) && right.some(hasValue(value));
  }
  if ([left, right].every(is.plainObject)) {
    return !Object.entries(left).some(hasEntry(value)) && Object.entries(right).some(hasEntry(value));
  }
  return right === value;
}
function compareNumbers(previousData, data, options) {
  var actual = options.actual, key = options.key, previous = options.previous, type = options.type;
  var left = nested(previousData, key);
  var right = nested(data, key);
  var changed = [left, right].every(is.number) && (type === "increased" ? left < right : left > right);
  if (!is.undefined(actual)) {
    changed = changed && right === actual;
  }
  if (!is.undefined(previous)) {
    changed = changed && left === previous;
  }
  return changed;
}
function compareValues(previousData, data, options) {
  var key = options.key, type = options.type, value = options.value;
  var left = nested(previousData, key);
  var right = nested(data, key);
  var primary = type === "added" ? left : right;
  var secondary = type === "added" ? right : left;
  if (!is.nullOrUndefined(value)) {
    if (is.defined(primary)) {
      if (is.array(primary) || is.plainObject(primary)) {
        return checkEquality(primary, secondary, value);
      }
    } else {
      return equal(secondary, value);
    }
    return false;
  }
  if ([left, right].every(is.array)) {
    return !secondary.every(isEqualPredicate(primary));
  }
  if ([left, right].every(is.plainObject)) {
    return hasExtraKeys(Object.keys(primary), Object.keys(secondary));
  }
  return ![left, right].every(function(d) {
    return is.primitive(d) && is.defined(d);
  }) && (type === "added" ? !is.defined(left) && is.defined(right) : is.defined(left) && !is.defined(right));
}
function getIterables(previousData, data, _a) {
  var _b = _a === void 0 ? {} : _a, key = _b.key;
  var left = nested(previousData, key);
  var right = nested(data, key);
  if (!isSameType(left, right)) {
    throw new TypeError("Inputs have different types");
  }
  if (!canHaveLength(left, right)) {
    throw new TypeError("Inputs don't have length");
  }
  if ([left, right].every(is.plainObject)) {
    left = Object.keys(left);
    right = Object.keys(right);
  }
  return [left, right];
}
function hasEntry(input) {
  return function(_a) {
    var key = _a[0], value = _a[1];
    if (is.array(input)) {
      return equal(input, value) || input.some(function(d) {
        return equal(d, value) || is.array(value) && isEqualPredicate(value)(d);
      });
    }
    if (is.plainObject(input) && input[key]) {
      return !!input[key] && equal(input[key], value);
    }
    return equal(input, value);
  };
}
function hasExtraKeys(left, right) {
  return right.some(function(d) {
    return !left.includes(d);
  });
}
function hasValue(input) {
  return function(value) {
    if (is.array(input)) {
      return input.some(function(d) {
        return equal(d, value) || is.array(value) && isEqualPredicate(value)(d);
      });
    }
    return equal(input, value);
  };
}
function includesOrEqualsTo(previousValue, value) {
  return is.array(previousValue) ? previousValue.some(function(d) {
    return equal(d, value);
  }) : equal(previousValue, value);
}
function isEqualPredicate(data) {
  return function(value) {
    return data.some(function(d) {
      return equal(d, value);
    });
  };
}
function isSameType() {
  var arguments_ = [];
  for (var _i = 0; _i < arguments.length; _i++) {
    arguments_[_i] = arguments[_i];
  }
  return arguments_.every(is.array) || arguments_.every(is.number) || arguments_.every(is.plainObject) || arguments_.every(is.string);
}
function nested(data, property) {
  if (is.plainObject(data) || is.array(data)) {
    if (is.string(property)) {
      var props = property.split(".");
      return props.reduce(function(acc, d) {
        return acc && acc[d];
      }, data);
    }
    if (is.number(property)) {
      return data[property];
    }
    return data;
  }
  return data;
}
export {
  canHaveLength,
  checkEquality,
  compareNumbers,
  compareValues,
  getIterables,
  hasEntry,
  hasExtraKeys,
  hasValue,
  includesOrEqualsTo,
  isEqualPredicate,
  isSameType,
  nested
};
//# sourceMappingURL=helpers.js.map
