"use strict";

import { sha256 } from 'js-sha256';
import { createRoomPresence } from './createRoomPresence.xmpp';
import { setMeAsOwner } from './setMeAsOwner.xmpp';
import { roomConfig } from './roomConfig.xmpp';
import { CONFERENCE_DOMAIN } from '../../helpers/constants/PLATFORM_CONSTANTS';
import { pushSubscriptionService } from '../../services/pushSubscriptionService';
export async function createRoom(title, description, client) {
  const randomNumber = Math.round(Math.random() * 100_000);
  const chatNameWithSalt = title + Date.now() + randomNumber;
  const roomHash = sha256(chatNameWithSalt);
  const roomId = `${roomHash}${CONFERENCE_DOMAIN}`;
  try {
    await createRoomPresence(roomId, client);
    await setMeAsOwner(roomId, client);
    await roomConfig(roomId, title, description, client);
    const userNick = client.jid?.getLocal();
    await pushSubscriptionService.subscribeToRoom(client, roomId, userNick).catch(error => {
      console.error('Failed to subscribe to new room for push:', error);
    });
  } catch (error) {
    console.log(error);
  }
  return roomId;
}
//# sourceMappingURL=createRoom.xmpp.js.map