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";
import { compareValues, nested, includesOrEqualsTo, compareNumbers, getIterables } from "./helpers.js";
function treeChanges(previousData, data) {
  if ([previousData, data].some(is.nullOrUndefined)) {
    throw new Error("Missing required parameters");
  }
  if (![previousData, data].every(function(d) {
    return is.plainObject(d) || is.array(d);
  })) {
    throw new Error("Expected plain objects or array");
  }
  var added = function(key, value) {
    try {
      return compareValues(previousData, data, { key, type: "added", value });
    } catch (_a) {
      return false;
    }
  };
  var changed = function(key, actual, previous) {
    try {
      var left = nested(previousData, key);
      var right = nested(data, key);
      var hasActual = is.defined(actual);
      var hasPrevious = is.defined(previous);
      if (hasActual || hasPrevious) {
        var leftComparator = hasPrevious ? includesOrEqualsTo(previous, left) : !includesOrEqualsTo(actual, left);
        var rightComparator = includesOrEqualsTo(actual, right);
        return leftComparator && rightComparator;
      }
      if ([left, right].every(is.array) || [left, right].every(is.plainObject)) {
        return !equal(left, right);
      }
      return left !== right;
    } catch (_a) {
      return false;
    }
  };
  var changedFrom = function(key, previous, actual) {
    if (!is.defined(key)) {
      return false;
    }
    try {
      var left = nested(previousData, key);
      var right = nested(data, key);
      var hasActual = is.defined(actual);
      return includesOrEqualsTo(previous, left) && (hasActual ? includesOrEqualsTo(actual, right) : !hasActual);
    } catch (_a) {
      return false;
    }
  };
  var changedTo = function(key, actual) {
    if (!is.defined(key)) {
      return false;
    }
    if (process.env.NODE_ENV === "development") {
      console.warn("`changedTo` is deprecated! Replace it with `change`");
    }
    return changed(key, actual);
  };
  var decreased = function(key, actual, previous) {
    if (!is.defined(key)) {
      return false;
    }
    try {
      return compareNumbers(previousData, data, { key, actual, previous, type: "decreased" });
    } catch (_a) {
      return false;
    }
  };
  var emptied = function(key) {
    try {
      var _a = getIterables(previousData, data, { key }), left = _a[0], right = _a[1];
      return !!left.length && !right.length;
    } catch (_b) {
      return false;
    }
  };
  var filled = function(key) {
    try {
      var _a = getIterables(previousData, data, { key }), left = _a[0], right = _a[1];
      return !left.length && !!right.length;
    } catch (_b) {
      return false;
    }
  };
  var increased = function(key, actual, previous) {
    if (!is.defined(key)) {
      return false;
    }
    try {
      return compareNumbers(previousData, data, { key, actual, previous, type: "increased" });
    } catch (_a) {
      return false;
    }
  };
  var removed = function(key, value) {
    try {
      return compareValues(previousData, data, { key, type: "removed", value });
    } catch (_a) {
      return false;
    }
  };
  return { added, changed, changedFrom, changedTo, decreased, emptied, filled, increased, removed };
}
export {
  treeChanges as default
};
//# sourceMappingURL=index.js.map
