"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 create_image_file_selection_fn_exports = {};
__export(create_image_file_selection_fn_exports, {
  createImageFileSelectionFn: () => createImageFileSelectionFn
});
module.exports = __toCommonJS(create_image_file_selection_fn_exports);
var import_create_open_media_manager_fn = require("./create-open-media-manager-fn.js");
var import_types = require("./types.js");
const createImageFileSelectionFn = (services) => {
  const openMediaManager = (0, import_create_open_media_manager_fn.createOpenMediaManagerFn)();
  if (!openMediaManager) {
    return void 0;
  }
  return (updateEntity, options, onCancel) => openMediaManager({
    mediaType: import_types.MediaManagerMediaType.IMAGE,
    appDefId: services.wixInstance().appDefId,
    isMultiSelect: options.multiple
  }).then((items) => {
    const imageData = items.map(
      ({
        title,
        uri,
        height,
        width
      }) => ({
        id: uri,
        height,
        width,
        original_file_name: title,
        file_name: uri
      })
    );
    updateEntity({
      data: imageData,
      // @ts-expect-error
      index: options.index
    });
  }).catch(onCancel);
};
//# sourceMappingURL=create-image-file-selection-fn.js.map
