import { isSSR } from "../is-ssr.js";
const createOpenMediaManagerFn = () => {
  if (isSSR()) {
    return void 0;
  }
  const mediaManagerInstance = window.editorSDK || window.ModuleRegistry;
  const isInEditor = mediaManagerInstance && "editor" in mediaManagerInstance;
  const isInBM = mediaManagerInstance && "registeredMethods" in mediaManagerInstance && mediaManagerInstance.registeredMethods && typeof mediaManagerInstance.registeredMethods === "object" && "mediaManager.open" in mediaManagerInstance.registeredMethods;
  if (!mediaManagerInstance || !isInEditor && !isInBM) {
    return void 0;
  }
  return async ({ mediaType, isMultiSelect, appDefId }) => {
    return "editor" in mediaManagerInstance ? mediaManagerInstance.editor.openMediaPanel("", {
      mediaType,
      isMultiSelect
    }) : new Promise((resolve, reject) => {
      mediaManagerInstance.invoke("mediaManager.open", mediaType, appDefId || "ricos", {
        multiSelect: isMultiSelect,
        onSuccess: (data) => resolve(data.items),
        onCancel: reject
      });
    });
  };
};
export {
  createOpenMediaManagerFn
};
//# sourceMappingURL=create-open-media-manager-fn.js.map
