import { getIdentity } from '../auth/auth.ic';
import { createDeckBucketActor, createManagerActor, initDeckBucket } from '../../utils/deck.utils';
import { fromArray, fromTimestamp } from '../../utils/did.utils';
export const getSlide = (deckId, slideId) => {
  return new Promise(async (resolve, reject) => {
    const identity = getIdentity();
    if (!identity) {
      reject('No internet identity.');
      return;
    }
    try {
      const managerActor = await createManagerActor({ identity });
      const bucket = await initDeckBucket({ managerActor, deckId });
      const deckBucket = await createDeckBucketActor({ identity, bucket });
      const slide = await deckBucket.getSlide(slideId);
      const data = await fromArray(slide.data);
      resolve({
        id: slideId,
        data: Object.assign(Object.assign({}, data), { created_at: fromTimestamp(slide.created_at), updated_at: fromTimestamp(slide.updated_at) })
      });
    }
    catch (err) {
      reject(err);
    }
  });
};
