import { useColor as f, useGun as g, reactive as u, currentRoom as _, onMounted as k, watchEffect as x, openBlock as b, createElementBlock as v, renderSlot as C, createBaseVNode as w } from "./composables-9e873712.js";
import { forceGraph as y } from "./force-graph-fc7d8b24.js";
const D = { class: "flex" }, N = /* @__PURE__ */ w("div", {
  class: "bg-light-100 bg-opacity-70 dark-bg-dark-200 backdrop-blur-md backdrop-filter overflow-hidden max-h-60vh min-h-400",
  id: "graph"
}, null, -1), A = {
  __name: "PostGraph",
  emits: ["post"],
  setup(B, { emit: m }) {
    const s = f("deep"), n = g(), c = u({}), l = u([]);
    n.user(_.pub).get("posts").map().once(async (t, e) => {
      let h = e.slice(-87), d = e.slice(0, 44), p = e.slice(45, 89);
      for (let r of [d, p]) {
        let a = await n.get("#posts").get(r).then();
        try {
          a = JSON.parse(a);
        } catch {
        }
        let o = a;
        c[r] = {
          hash: r,
          color: s.hex(r),
          name: (o == null ? void 0 : o.title) || (o == null ? void 0 : o.statement) || r
        };
      }
      l.push({
        source: d,
        target: p,
        emoji: t,
        author: h
      });
    });
    const i = {};
    return k(() => {
      const t = y()(document.getElementById("graph")).nodeId("hash").nodeColor("color").nodeRelSize(4).linkDirectionalArrowLength(6).linkDirectionalArrowRelPos(1).linkLabel("emoji").linkCurvature((e) => i[e.index] = i[e.index] || Math.random() * 1 - 0.5).linkColor((e) => s.hex((e == null ? void 0 : e.author) || 0)).linkWidth((e) => 2).onNodeDragEnd((e) => {
        e.fx = e.x, e.fy = e.y;
      }).onNodeClick((e) => {
        t.centerAt(e.x, e.y, 1e3), t.zoom(4, 2e3);
      }).onNodeClick((e, h) => {
        m("post", e.hash);
      });
      x(() => t.graphData({ nodes: Object.values(c), links: l }));
    }), (t, e) => (b(), v("div", D, [
      N,
      C(t.$slots, "default")
    ]));
  }
};
export {
  A as default
};
//# sourceMappingURL=PostGraph-fcc7b834.js.map
