import { HocuspocusProvider } from '../../../../../node_modules/.pnpm/@hocuspocus_provider@2.15.2_y-protocols@1.0.6_yjs@13.6.26__yjs@13.6.26/node_modules/@hocuspocus/provider/dist/hocuspocus-provider.esm.js';
import { Awareness } from '../../../../../node_modules/.pnpm/y-protocols@1.0.6_yjs@13.6.26/node_modules/y-protocols/awareness.js';
import { Doc } from '../../../../../node_modules/.pnpm/yjs@13.6.26/node_modules/yjs/dist/yjs.js';

const defaults = {
  url: "ws://localhost:1234",
  room: "default"
};
const rooms = /* @__PURE__ */ new Map();
function connect(url, room) {
  const cacheId = `${url}:${room}`;
  if (!rooms.has(cacheId)) {
    const doc = new Doc({ guid: room, autoLoad: true });
    const awareness = new Awareness(doc);
    const provider = new HocuspocusProvider({
      url: url || defaults.url,
      name: room || defaults.room,
      document: doc,
      awareness,
      connect: true,
      broadcast: true,
      forceSyncInterval: 1e3,
      onConnect: () => {
        console.log("connected to", url, room);
      }
    });
    rooms.set(cacheId, { provider, doc, awareness });
  }
  return rooms.get(cacheId);
}

export { connect, rooms };
