import { getImageStudioPackage } from "./image-studio-opener-loader.js";
async function setupImageEditor(imageEditorWixSettings, rootElementId, fileName, onSave, onClose) {
  const { MediaImageStudio, MediaImageStudioEvents, MediaImageStudioMode } = await getImageStudioPackage();
  const resolvedImageEditorWixSettings = await imageEditorWixSettings;
  const mediaImageStudio = new MediaImageStudio({
    ...resolvedImageEditorWixSettings,
    metasiteId: resolvedImageEditorWixSettings.metaSiteId,
    appendTo: document.querySelector(`[id=${rootElementId}]`)
  });
  const imageDataSubscription = mediaImageStudio.once(
    MediaImageStudioEvents.ImageData,
    (imageData) => {
      const file = blobToFile(imageData, fileName);
      onSave(file);
    }
  );
  mediaImageStudio.once(MediaImageStudioEvents.Close, () => {
    imageDataSubscription.remove();
    mediaImageStudio.kill();
    onClose();
  });
  mediaImageStudio.show({
    mode: MediaImageStudioMode.Transform,
    fileId: fileName
  });
}
function blobToFile(blob, fileName) {
  blob.lastModified = (/* @__PURE__ */ new Date()).getTime();
  blob.name = fileName;
  blob.webkitRelativePath = "";
  return blob;
}
export {
  setupImageEditor
};
//# sourceMappingURL=image-editor-logic.js.map
