import { emitDeckPublished, publishDeck } from '../../utils/publish.deck.utils';
import { uploadResources } from '../../utils/publish.resources.utils';
import { publishOverview } from '../../utils/publish.overview.utils';
import { getStorageActor } from '../../utils/storage.utils';
import { emitDocPublished, publishDoc } from '../../utils/publish.doc.utils';
export const deckPublish = async ({ deck }) => {
  await uploadResources({ meta: deck.data.meta });
  const { storageUpload, publishData, deck: updatedDeck } = await publishDeck({ deck });
  await publishOverview({ storageUpload, publishData, dataId: updatedDeck.id });
  emitDeckPublished(deck);
  return updatedDeck;
};
export const docPublish = async ({ doc }) => {
  await uploadResources({ meta: doc.data.meta });
  const { storageUpload, publishData, doc: updatedDoc } = await publishDoc({ doc });
  await publishOverview({ storageUpload, publishData, dataId: updatedDoc.id });
  emitDocPublished(doc);
  return updatedDoc;
};
export const publishUrl = async () => {
  const { bucketId } = await getStorageActor();
  return `https://${bucketId.toText()}.raw.ic0.app`;
};
