"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var image_editor_logic_exports = {};
__export(image_editor_logic_exports, {
  setupImageEditor: () => setupImageEditor
});
module.exports = __toCommonJS(image_editor_logic_exports);
var import_image_studio_opener_loader = require("./image-studio-opener-loader.js");
async function setupImageEditor(imageEditorWixSettings, rootElementId, fileName, onSave, onClose) {
  const { MediaImageStudio, MediaImageStudioEvents, MediaImageStudioMode } = await (0, import_image_studio_opener_loader.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;
}
//# sourceMappingURL=image-editor-logic.js.map
