import { f as u, U as B, G as y, i as C, K as T, W as V, p as i, s as b, g as f, a0 as $, A as v, o as A, H as D, F as N } from "./index-CNUFa5l3.js";
import { t as W } from "./chunk-4BX2VUAB-C_NnimAy-9zhkU6MG.js";
import { r as X } from "./wardley-L42UT6IY-BjAkE_cs-li1xYed9.js";
import { t as F } from "./chunk-QZHKN3VN-DN6nBdn0-Dw_BErph.js";
var s = new F(() => ({
  cnt: 1,
  stack: [{
    id: 0,
    level: -1,
    name: "/",
    children: []
  }]
})), H = /* @__PURE__ */ i(() => {
  s.reset(), D();
}, "clear"), R = /* @__PURE__ */ i(() => s.records.stack[0], "getRoot"), z = /* @__PURE__ */ i(() => s.records.cnt, "getCount"), G = N.treeView, x = {
  clear: H,
  addNode: /* @__PURE__ */ i((e, t) => {
    for (; e <= s.records.stack[s.records.stack.length - 1].level; ) s.records.stack.pop();
    let a = {
      id: s.records.cnt++,
      level: e,
      name: t,
      children: []
    };
    s.records.stack[s.records.stack.length - 1].children.push(a), s.records.stack.push(a);
  }, "addNode"),
  getRoot: R,
  getCount: z,
  getConfig: /* @__PURE__ */ i(() => b(G, A().treeView), "getConfig"),
  getAccTitle: V,
  getAccDescription: T,
  getDiagramTitle: C,
  setAccDescription: y,
  setAccTitle: B,
  setDiagramTitle: u
}, I = /* @__PURE__ */ i((e) => {
  W(e, x), e.nodes.map((t) => x.addNode(t.indent ? parseInt(t.indent) : 0, t.name));
}, "populate"), S = { parse: /* @__PURE__ */ i(async (e) => {
  let t = await X("treeView", e);
  f.debug(t), I(t);
}, "parse") }, E = /* @__PURE__ */ i((e, t, a, n, l) => {
  let c = n.append("text").text(a.name).attr("dominant-baseline", "middle").attr("class", "treeView-node-label"), { height: g, width: r } = c.node().getBBox(), d = g + l.paddingY * 2, o = r + l.paddingX * 2;
  c.attr("x", e + l.paddingX), c.attr("y", t + d / 2), a.BBox = {
    x: e,
    y: t,
    width: o,
    height: d
  };
}, "positionLabel"), k = /* @__PURE__ */ i((e, t, a, n, l, c) => e.append("line").attr("x1", t).attr("y1", a).attr("x2", n).attr("y2", l).attr("stroke-width", c).attr("class", "treeView-node-line"), "positionLine"), K = /* @__PURE__ */ i((e, t, a) => {
  let n = 0, l = 0, c = /* @__PURE__ */ i((r, d, o, p) => {
    let w = p * (o.rowIndent + o.paddingX);
    E(w, n, d, r, o);
    let { height: h, width: m } = d.BBox;
    k(r, w - o.rowIndent, n + h / 2, w, n + h / 2, o.lineThickness), l = Math.max(l, w + m), n += h;
  }, "drawNode"), g = /* @__PURE__ */ i((r, d = 0) => {
    c(e, r, a, d), r.children.forEach((h) => {
      g(h, d + 1);
    });
    let { x: o, y: p, height: w } = r.BBox;
    if (r.children.length) {
      let { y: h, height: m } = r.children[r.children.length - 1].BBox;
      k(e, o + a.paddingX, p + w, o + a.paddingX, h + m / 2 + a.lineThickness / 2, a.lineThickness);
    }
  }, "processNode");
  return g(t), {
    totalHeight: n,
    totalWidth: l
  };
}, "drawTree"), L = { draw: /* @__PURE__ */ i((e, t, a, n) => {
  f.debug(`Rendering treeView diagram
` + e);
  let l = n.db, c = l.getRoot(), g = l.getConfig(), r = $(t), d = r.append("g");
  d.attr("class", "tree-view");
  let { totalHeight: o, totalWidth: p } = K(d, c, g);
  r.attr("viewBox", `-${g.lineThickness / 2} 0 ${p} ${o}`), v(r, o, p, g.useMaxWidth);
}, "draw") }, M = {
  labelFontSize: "16px",
  labelColor: "black",
  lineColor: "black"
}, Q = {
  db: x,
  renderer: L,
  parser: S,
  styles: /* @__PURE__ */ i(({ treeView: e }) => {
    let { labelFontSize: t, labelColor: a, lineColor: n } = b(M, e);
    return `
    .treeView-node-label {
        font-size: ${t};
        fill: ${a};
    }
    .treeView-node-line {
        stroke: ${n};
    }
    `;
  }, "styles")
};
export {
  Q as diagram
};
