import { __name as e, log as t } from "./chunk-AGHRB4JF.js";
import { clear as n, configureSvgSize as r, defaultConfig_default as i, getAccDescription as a, getAccTitle as o, getConfig as s, getDiagramTitle as c, setAccDescription as l, setAccTitle as u, setDiagramTitle as d } from "./chunk-ICPOFSXX.js";
import { selectSvgElement as f } from "./chunk-426QAEUC.js";
import { cleanAndMerge as p } from "./chunk-5PVQY5BW.js";
import { populateCommonDb as m } from "./chunk-4BX2VUAB.js";
import { parse as h } from "../../../../@mermaid-js/parser/dist/mermaid-parser.core.js";
import { ImperativeState as g } from "./chunk-QZHKN3VN.js";
//#region ../../node_modules/mermaid/dist/chunks/mermaid.core/diagram-5BDNPKRD.mjs
var _ = new g(() => ({
	cnt: 1,
	stack: [{
		id: 0,
		level: -1,
		name: "/",
		children: []
	}]
})), v = /* @__PURE__ */ e(() => {
	_.reset(), n();
}, "clear"), y = /* @__PURE__ */ e(() => _.records.stack[0], "getRoot"), b = /* @__PURE__ */ e(() => _.records.cnt, "getCount"), x = i.treeView, S = {
	clear: v,
	addNode: /* @__PURE__ */ e((e, t) => {
		for (; e <= _.records.stack[_.records.stack.length - 1].level;) _.records.stack.pop();
		let n = {
			id: _.records.cnt++,
			level: e,
			name: t,
			children: []
		};
		_.records.stack[_.records.stack.length - 1].children.push(n), _.records.stack.push(n);
	}, "addNode"),
	getRoot: y,
	getCount: b,
	getConfig: /* @__PURE__ */ e(() => p(x, s().treeView), "getConfig"),
	getAccTitle: o,
	getAccDescription: a,
	getDiagramTitle: c,
	setAccDescription: l,
	setAccTitle: u,
	setDiagramTitle: d
}, C = /* @__PURE__ */ e((e) => {
	m(e, S), e.nodes.map((e) => S.addNode(e.indent ? parseInt(e.indent) : 0, e.name));
}, "populate"), w = { parse: /* @__PURE__ */ e(async (e) => {
	let n = await h("treeView", e);
	t.debug(n), C(n);
}, "parse") }, T = /* @__PURE__ */ e((e, t, n, r, i) => {
	let a = r.append("text").text(n.name).attr("dominant-baseline", "middle").attr("class", "treeView-node-label"), { height: o, width: s } = a.node().getBBox(), c = o + i.paddingY * 2, l = s + i.paddingX * 2;
	a.attr("x", e + i.paddingX), a.attr("y", t + c / 2), n.BBox = {
		x: e,
		y: t,
		width: l,
		height: c
	};
}, "positionLabel"), E = /* @__PURE__ */ e((e, t, n, r, i, a) => e.append("line").attr("x1", t).attr("y1", n).attr("x2", r).attr("y2", i).attr("stroke-width", a).attr("class", "treeView-node-line"), "positionLine"), D = /* @__PURE__ */ e((t, n, r) => {
	let i = 0, a = 0, o = /* @__PURE__ */ e((e, t, n, r) => {
		let o = r * (n.rowIndent + n.paddingX);
		T(o, i, t, e, n);
		let { height: s, width: c } = t.BBox;
		E(e, o - n.rowIndent, i + s / 2, o, i + s / 2, n.lineThickness), a = Math.max(a, o + c), i += s;
	}, "drawNode"), s = /* @__PURE__ */ e((e, n = 0) => {
		o(t, e, r, n), e.children.forEach((e) => {
			s(e, n + 1);
		});
		let { x: i, y: a, height: c } = e.BBox;
		if (e.children.length) {
			let { y: n, height: o } = e.children[e.children.length - 1].BBox;
			E(t, i + r.paddingX, a + c, i + r.paddingX, n + o / 2 + r.lineThickness / 2, r.lineThickness);
		}
	}, "processNode");
	return s(n), {
		totalHeight: i,
		totalWidth: a
	};
}, "drawTree"), O = { draw: /* @__PURE__ */ e((e, n, i, a) => {
	t.debug("Rendering treeView diagram\n" + e);
	let o = a.db, s = o.getRoot(), c = o.getConfig(), l = f(n), u = l.append("g");
	u.attr("class", "tree-view");
	let { totalHeight: d, totalWidth: p } = D(u, s, c);
	l.attr("viewBox", `-${c.lineThickness / 2} 0 ${p} ${d}`), r(l, d, p, c.useMaxWidth);
}, "draw") }, k = {
	labelFontSize: "16px",
	labelColor: "black",
	lineColor: "black"
}, A = {
	db: S,
	renderer: O,
	parser: w,
	styles: /* @__PURE__ */ e(({ treeView: e }) => {
		let { labelFontSize: t, labelColor: n, lineColor: r } = p(k, e);
		return `
    .treeView-node-label {
        font-size: ${t};
        fill: ${n};
    }
    .treeView-node-line {
        stroke: ${r};
    }
    `;
	}, "styles")
};
//#endregion
export { A as diagram };
