import { partition as h } from "../util.js";
import m from "../../../../../../lodash-es@4.17.22/node_modules/lodash-es/sortBy.js";
import l from "../../../../../../lodash-es@4.17.22/node_modules/lodash-es/forEach.js";
import v from "../../../../../../lodash-es@4.17.22/node_modules/lodash-es/flatten.js";
import b from "../../../../../../lodash-es@4.17.22/node_modules/lodash-es/last.js";
function I(e, t) {
  var r = h(e, function(o) {
    return Object.prototype.hasOwnProperty.call(o, "barycenter");
  }), i = r.lhs, u = m(r.rhs, function(o) {
    return -o.i;
  }), s = [], f = 0, a = 0, n = 0;
  i.sort(g(!!t)), n = p(s, u, n), l(i, function(o) {
    n += o.vs.length, s.push(o.vs), f += o.barycenter * o.weight, a += o.weight, n = p(s, u, n);
  });
  var c = { vs: v(s) };
  return a && (c.barycenter = f / a, c.weight = a), c;
}
function p(e, t, r) {
  for (var i; t.length && (i = b(t)).i <= r; )
    t.pop(), e.push(i.vs), r++;
  return r;
}
function g(e) {
  return function(t, r) {
    return t.barycenter < r.barycenter ? -1 : t.barycenter > r.barycenter ? 1 : e ? r.i - t.i : t.i - r.i;
  };
}
export {
  I as sort
};
