import { reactive as p, onMounted as g, watchEffect as k, createElementBlock as x, openBlock as b, createElementVNode as v, renderSlot as _ } from "vue";
import { useColor as C, useGun as w, currentRoom as y } from "./composables-BAZQlC3e.js";
import { forceGraph as D } from "./force-graph-VzmpCvoV.js";
const E = { class: "flex" }, R = {
  __name: "PostGraph",
  emits: ["post"],
  setup(N, { emit: u }) {
    const f = u, a = C("deep"), s = w(), l = p({}), c = p([]);
    s.user(y.pub).get("posts").map().once(async (t, e) => {
      let d = e.slice(-87), h = e.slice(0, 44), m = e.slice(45, 89);
      for (let r of [h, m]) {
        let n = await s.get("#posts").get(r).then();
        try {
          n = JSON.parse(n);
        } catch {
        }
        let o = n;
        l[r] = {
          hash: r,
          color: a.hex(r),
          name: (o == null ? void 0 : o.title) || (o == null ? void 0 : o.statement) || r
        };
      }
      c.push({
        source: h,
        target: m,
        emoji: t,
        author: d
      });
    });
    const i = {};
    return g(() => {
      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) => a.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, d) => {
        f("post", e.hash);
      });
      k(() => t.graphData({ nodes: Object.values(l), links: c }));
    }), (t, e) => (b(), x("div", E, [
      e[0] || (e[0] = v("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)),
      _(t.$slots, "default")
    ]));
  }
};
export {
  R as default
};
//# sourceMappingURL=PostGraph-Bbmgjz2Q.js.map
