import h from "../../../../../../lodash-es@4.17.22/node_modules/lodash-es/forEach.js";
import c from "../../../../../../lodash-es@4.17.22/node_modules/lodash-es/isUndefined.js";
import u from "../../../../../../lodash-es@4.17.22/node_modules/lodash-es/filter.js";
import m from "../../../../../../lodash-es@4.17.22/node_modules/lodash-es/map.js";
import a from "../../../../../../lodash-es@4.17.22/node_modules/lodash-es/pick.js";
function l(i, t) {
  var f = {};
  h(i, function(e, n) {
    var r = f[e.v] = {
      indegree: 0,
      in: [],
      out: [],
      vs: [e.v],
      i: n
    };
    c(e.barycenter) || (r.barycenter = e.barycenter, r.weight = e.weight);
  }), h(t.edges(), function(e) {
    var n = f[e.v], r = f[e.w];
    !c(n) && !c(r) && (r.indegree++, n.out.push(f[e.w]));
  });
  var o = u(f, function(e) {
    return !e.indegree;
  });
  return v(o);
}
function v(i) {
  var t = [];
  function f(n) {
    return function(r) {
      r.merged || (c(r.barycenter) || c(n.barycenter) || r.barycenter >= n.barycenter) && p(n, r);
    };
  }
  function o(n) {
    return function(r) {
      r.in.push(n), --r.indegree === 0 && i.push(r);
    };
  }
  for (; i.length; ) {
    var e = i.pop();
    t.push(e), h(e.in.reverse(), f(e)), h(e.out, o(e));
  }
  return m(
    u(t, function(n) {
      return !n.merged;
    }),
    function(n) {
      return a(n, ["vs", "i", "barycenter", "weight"]);
    }
  );
}
function p(i, t) {
  var f = 0, o = 0;
  i.weight && (f += i.barycenter * i.weight, o += i.weight), t.weight && (f += t.barycenter * t.weight, o += t.weight), i.vs = t.vs.concat(i.vs), i.barycenter = f / o, i.weight = o, i.i = Math.min(t.i, i.i), t.merged = !0;
}
export {
  l as resolveConflicts
};
