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