import j from "./array.js";
import r from "./constant.js";
import k from "./descending.js";
import q from "./identity.js";
import { tau as M } from "./math.js";
function F() {
  var m = q, i = k, a = null, p = r(0), c = r(M), h = r(0);
  function t(n) {
    var e, u = (n = j(n)).length, s, w, y = 0, f = new Array(u), o = new Array(u), g = +p.apply(this, arguments), A = Math.min(M, Math.max(-M, c.apply(this, arguments) - g)), d, V = Math.min(Math.abs(A) / u, h.apply(this, arguments)), b = V * (A < 0 ? -1 : 1), l;
    for (e = 0; e < u; ++e)
      (l = o[f[e] = e] = +m(n[e], e, n)) > 0 && (y += l);
    for (i != null ? f.sort(function(v, x) {
      return i(o[v], o[x]);
    }) : a != null && f.sort(function(v, x) {
      return a(n[v], n[x]);
    }), e = 0, w = y ? (A - u * b) / y : 0; e < u; ++e, g = d)
      s = f[e], l = o[s], d = g + (l > 0 ? l * w : 0) + b, o[s] = {
        data: n[s],
        index: e,
        value: l,
        startAngle: g,
        endAngle: d,
        padAngle: V
      };
    return o;
  }
  return t.value = function(n) {
    return arguments.length ? (m = typeof n == "function" ? n : r(+n), t) : m;
  }, t.sortValues = function(n) {
    return arguments.length ? (i = n, a = null, t) : i;
  }, t.sort = function(n) {
    return arguments.length ? (a = n, i = null, t) : a;
  }, t.startAngle = function(n) {
    return arguments.length ? (p = typeof n == "function" ? n : r(+n), t) : p;
  }, t.endAngle = function(n) {
    return arguments.length ? (c = typeof n == "function" ? n : r(+n), t) : c;
  }, t.padAngle = function(n) {
    return arguments.length ? (h = typeof n == "function" ? n : r(+n), t) : h;
  }, t;
}
export {
  F as default
};
