import { defineComponent as p, ref as d, useColor as m, useGun as f, reactive as g, currentRoom as b, useMates as _, computed as k, user as v, onMounted as w, watchEffect as x, useResizeObserver as y, openBlock as C, createElementBlock as j, createBaseVNode as E } from "./composables-Ci32s3jE.js";
import { forceGraph as D } from "./force-graph-3v6U1nLK.js";
const R = /* @__PURE__ */ E("div", { id: "graph" }, null, -1), B = [
  R
], z = /* @__PURE__ */ p({
  __name: "UserGraph",
  emits: ["user"],
  setup(G, { emit: u }) {
    const s = d(null), i = u, c = m("deep"), a = f(), n = g({});
    a.user(b.pub).get("space").map().once(async (e, t) => {
      n[t] = {
        pub: t,
        name: await a.user(t).get("profile").get("name").then(),
        color: c.hex(t),
        links: _(t)
      };
    });
    const l = k(() => {
      let e = [];
      return Object.values(n).forEach((t) => {
        Object.entries(t.links).forEach((r) => {
          !n[r[0]] || !r[1].text || e.push({
            source: t.pub,
            target: r[0],
            emoji: r[1].emoji,
            back: r[1].back
          });
        });
      }), e;
    }), o = D().width(600).nodeId("pub").nodeColor("color").nodeVal((e) => e.pub == v.pub ? 10 : 1).nodeRelSize(4).linkDirectionalArrowLength(4).linkDirectionalArrowRelPos(1).linkLabel("emoji").linkCurvature(0.2).linkColor((e) => {
      var t;
      return c.hex(((t = e.source) == null ? void 0 : t.pub) || 0);
    }).linkWidth((e) => e.back ? 3 : 1).onNodeDragEnd((e) => {
      e.fx = e.x, e.fy = e.y;
    }).onNodeClick((e) => {
      o.centerAt(e.x, e.y, 1e3), o.zoom(4, 2e3);
    }).onNodeClick((e) => {
      i("user", e.pub);
    });
    return w(() => {
      o(document.getElementById("graph"));
    }), x(() => o.graphData({ nodes: Object.values(n), links: l.value })), y(s, (e) => {
      const t = e[0], { width: r, height: h } = t.contentRect;
      o.width(r), o.height(h);
    }), (e, t) => (C(), j("div", {
      class: "bg-light-700 dark-bg-dark-500 overflow-none w-full max-w-90vw max-h-90vh h-full",
      ref_key: "graph",
      ref: s
    }, B, 512));
  }
});
export {
  z as default
};
//# sourceMappingURL=UserGraph-CXAM1pXI.js.map
