import { f as e } from "./custom-D-TzPpWT.js";
import { g as t, h as n } from "./src-BuisGndr.js";
import { B as r, C as i, U as a, _ as o, a as s, b as c, c as l, d as u, v as d, z as f } from "./chunk-ABZYJK2D-DDrmE3Q7.js";
import { t as p } from "./ordinal-C55HfHHp.js";
import { n as m } from "./path-DNvJyUE8.js";
import { p as h } from "./math-H49DsxYR.js";
import { t as g } from "./arc-vLgDTVZZ.js";
import { t as _ } from "./array-CApNbSU9.js";
import { f as v, r as y } from "./chunk-S3R3BYOJ-CG6GoSCd.js";
import { t as b } from "./mermaid-parser.core-B84fnaGG.js";
import { t as x } from "./chunk-4BX2VUAB-BZTgbbzC.js";
//#region node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/descending.js
function S(e, t) {
	return t < e ? -1 : t > e ? 1 : t >= e ? 0 : NaN;
}
//#endregion
//#region node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/identity.js
function C(e) {
	return e;
}
//#endregion
//#region node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/pie.js
function w() {
	var e = C, t = S, n = null, r = m(0), i = m(h), a = m(0);
	function o(o) {
		var s, c = (o = _(o)).length, l, u, d = 0, f = Array(c), p = Array(c), m = +r.apply(this, arguments), g = Math.min(h, Math.max(-h, i.apply(this, arguments) - m)), v, y = Math.min(Math.abs(g) / c, a.apply(this, arguments)), b = y * (g < 0 ? -1 : 1), x;
		for (s = 0; s < c; ++s) (x = p[f[s] = s] = +e(o[s], s, o)) > 0 && (d += x);
		for (t == null ? n != null && f.sort(function(e, t) {
			return n(o[e], o[t]);
		}) : f.sort(function(e, n) {
			return t(p[e], p[n]);
		}), s = 0, u = d ? (g - c * b) / d : 0; s < c; ++s, m = v) l = f[s], x = p[l], v = m + (x > 0 ? x * u : 0) + b, p[l] = {
			data: o[l],
			index: s,
			value: x,
			startAngle: m,
			endAngle: v,
			padAngle: y
		};
		return p;
	}
	return o.value = function(t) {
		return arguments.length ? (e = typeof t == "function" ? t : m(+t), o) : e;
	}, o.sortValues = function(e) {
		return arguments.length ? (t = e, n = null, o) : t;
	}, o.sort = function(e) {
		return arguments.length ? (n = e, t = null, o) : n;
	}, o.startAngle = function(e) {
		return arguments.length ? (r = typeof e == "function" ? e : m(+e), o) : r;
	}, o.endAngle = function(e) {
		return arguments.length ? (i = typeof e == "function" ? e : m(+e), o) : i;
	}, o.padAngle = function(e) {
		return arguments.length ? (a = typeof e == "function" ? e : m(+e), o) : a;
	}, o;
}
//#endregion
//#region node_modules/.pnpm/mermaid@11.12.0/node_modules/mermaid/dist/chunks/mermaid.core/pieDiagram-ADFJNKIX.mjs
var T = u.pie, E = {
	sections: /* @__PURE__ */ new Map(),
	showData: !1,
	config: T
}, D = E.sections, O = E.showData, k = structuredClone(T), A = {
	getConfig: /* @__PURE__ */ n(() => structuredClone(k), "getConfig"),
	clear: /* @__PURE__ */ n(() => {
		D = /* @__PURE__ */ new Map(), O = E.showData, s();
	}, "clear"),
	setDiagramTitle: a,
	getDiagramTitle: i,
	setAccTitle: r,
	getAccTitle: d,
	setAccDescription: f,
	getAccDescription: o,
	addSection: /* @__PURE__ */ n(({ label: e, value: n }) => {
		if (n < 0) throw Error(`"${e}" has invalid value: ${n}. Negative values are not allowed in pie charts. All slice values must be >= 0.`);
		D.has(e) || (D.set(e, n), t.debug(`added new section: ${e}, with value: ${n}`));
	}, "addSection"),
	getSections: /* @__PURE__ */ n(() => D, "getSections"),
	setShowData: /* @__PURE__ */ n((e) => {
		O = e;
	}, "setShowData"),
	getShowData: /* @__PURE__ */ n(() => O, "getShowData")
}, j = /* @__PURE__ */ n((e, t) => {
	x(e, t), t.setShowData(e.showData), e.sections.map(t.addSection);
}, "populateDb"), M = { parse: /* @__PURE__ */ n(async (e) => {
	let n = await b("pie", e);
	t.debug(n), j(n, A);
}, "parse") }, N = /* @__PURE__ */ n((e) => `
  .pieCircle{
    stroke: ${e.pieStrokeColor};
    stroke-width : ${e.pieStrokeWidth};
    opacity : ${e.pieOpacity};
  }
  .pieOuterCircle{
    stroke: ${e.pieOuterStrokeColor};
    stroke-width: ${e.pieOuterStrokeWidth};
    fill: none;
  }
  .pieTitleText {
    text-anchor: middle;
    font-size: ${e.pieTitleTextSize};
    fill: ${e.pieTitleTextColor};
    font-family: ${e.fontFamily};
  }
  .slice {
    font-family: ${e.fontFamily};
    fill: ${e.pieSectionTextColor};
    font-size:${e.pieSectionTextSize};
    // fill: white;
  }
  .legend text {
    fill: ${e.pieLegendTextColor};
    font-family: ${e.fontFamily};
    font-size: ${e.pieLegendTextSize};
  }
`, "getStyles"), P = /* @__PURE__ */ n((e) => {
	let t = [...e.values()].reduce((e, t) => e + t, 0), n = [...e.entries()].map(([e, t]) => ({
		label: e,
		value: t
	})).filter((e) => e.value / t * 100 >= 1).sort((e, t) => t.value - e.value);
	return w().value((e) => e.value)(n);
}, "createPieArcs"), F = {
	parser: M,
	db: A,
	renderer: { draw: /* @__PURE__ */ n((n, r, i, a) => {
		t.debug("rendering pie chart\n" + n);
		let o = a.db, s = c(), u = y(o.getConfig(), s.pie), d = e(r), f = d.append("g");
		f.attr("transform", "translate(225,225)");
		let { themeVariables: m } = s, [h] = v(m.pieOuterStrokeWidth);
		h ??= 2;
		let _ = u.textPosition, b = g().innerRadius(0).outerRadius(185), x = g().innerRadius(185 * _).outerRadius(185 * _);
		f.append("circle").attr("cx", 0).attr("cy", 0).attr("r", 185 + h / 2).attr("class", "pieOuterCircle");
		let S = o.getSections(), C = P(S), w = [
			m.pie1,
			m.pie2,
			m.pie3,
			m.pie4,
			m.pie5,
			m.pie6,
			m.pie7,
			m.pie8,
			m.pie9,
			m.pie10,
			m.pie11,
			m.pie12
		], T = 0;
		S.forEach((e) => {
			T += e;
		});
		let E = C.filter((e) => (e.data.value / T * 100).toFixed(0) !== "0"), D = p(w);
		f.selectAll("mySlices").data(E).enter().append("path").attr("d", b).attr("fill", (e) => D(e.data.label)).attr("class", "pieCircle"), f.selectAll("mySlices").data(E).enter().append("text").text((e) => (e.data.value / T * 100).toFixed(0) + "%").attr("transform", (e) => "translate(" + x.centroid(e) + ")").style("text-anchor", "middle").attr("class", "slice"), f.append("text").text(o.getDiagramTitle()).attr("x", 0).attr("y", -400 / 2).attr("class", "pieTitleText");
		let O = [...S.entries()].map(([e, t]) => ({
			label: e,
			value: t
		})), k = f.selectAll(".legend").data(O).enter().append("g").attr("class", "legend").attr("transform", (e, t) => {
			let n = 22 * O.length / 2;
			return "translate(216," + (t * 22 - n) + ")";
		});
		k.append("rect").attr("width", 18).attr("height", 18).style("fill", (e) => D(e.label)).style("stroke", (e) => D(e.label)), k.append("text").attr("x", 22).attr("y", 14).text((e) => o.getShowData() ? `${e.label} [${e.value}]` : e.label);
		let A = 512 + Math.max(...k.selectAll("text").nodes().map((e) => e?.getBoundingClientRect().width ?? 0));
		d.attr("viewBox", `0 0 ${A} 450`), l(d, 450, A, u.useMaxWidth);
	}, "draw") },
	styles: N
};
//#endregion
export { F as diagram };
