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