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