import { defineComponent as h, ref as p, useColor as d, useGun as f, reactive as m, currentRoom as g, useMates as b, computed as _, user as k, onMounted as v, watchEffect as w, useResizeObserver as x, openBlock as y, createElementBlock as C, createBaseVNode as j } from "./composables-108ad332.js";
import { forceGraph as E } from "./force-graph-17721763.js";
const D = /* @__PURE__ */ j("div", { id: "graph" }, null, -1), R = [
  D
], O = /* @__PURE__ */ h({
  __name: "UserGraph",
  emits: ["user"],
  setup(B, { emit: u }) {
    const s = p(null), c = d("deep"), a = f(), n = m({});
    a.user(g.pub).get("space").map().once(async (e, r) => {
      n[r] = {
        pub: r,
        name: await a.user(r).get("profile").get("name").then(),
        color: c.hex(r),
        links: b(r)
      };
    });
    const l = _(() => {
      let e = [];
      return Object.values(n).forEach((r) => {
        Object.entries(r.links).forEach((t) => {
          !n[t[0]] || !t[1].text || e.push({
            source: r.pub,
            target: t[0],
            emoji: t[1].emoji,
            back: t[1].back
          });
        });
      }), e;
    }), o = E().width(600).nodeId("pub").nodeColor("color").nodeVal((e) => e.pub == k.pub ? 10 : 1).nodeRelSize(4).linkDirectionalArrowLength(4).linkDirectionalArrowRelPos(1).linkLabel("emoji").linkCurvature(0.2).linkColor((e) => {
      var r;
      return c.hex(((r = e.source) == null ? void 0 : r.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) => {
      u("user", e.pub);
    });
    return v(() => {
      o(document.getElementById("graph"));
    }), w(() => o.graphData({ nodes: Object.values(n), links: l.value })), x(s, (e) => {
      const r = e[0], { width: t, height: i } = r.contentRect;
      o.width(t), o.height(i);
    }), (e, r) => (y(), C("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
    }, R, 512));
  }
});
export {
  O as default
};
//# sourceMappingURL=UserGraph-9d0c43d8.js.map
