import { useColor as g, useGun as _, reactive as u, currentRoom as k, onMounted as x, watchEffect as b, openBlock as v, createElementBlock as C, renderSlot as w, createBaseVNode as y } from "./composables-Ci32s3jE.js";
import { forceGraph as D } from "./force-graph-3v6U1nLK.js";
const N = { class: "flex" }, B = /* @__PURE__ */ y("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), R = {
  __name: "PostGraph",
  emits: ["post"],
  setup(E, { emit: m }) {
    const f = m, s = g("deep"), n = _(), c = u({}), l = u([]);
    n.user(k.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 x(() => {
      const t = D()(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) => {
        f("post", e.hash);
      });
      b(() => t.graphData({ nodes: Object.values(c), links: l }));
    }), (t, e) => (v(), C("div", N, [
      B,
      w(t.$slots, "default")
    ]));
  }
};
export {
  R as default
};
//# sourceMappingURL=PostGraph-CB0zCC2o.js.map
