import { createElement, Fragment } from "react";
import { SugaredField } from "@contember/binding";
const getImageFileDataExtractor = ({
  heightField,
  widthField
}) => ({
  staticRender: () => /* @__PURE__ */ createElement(Fragment, null, !!widthField && /* @__PURE__ */ createElement(SugaredField, {
    field: widthField
  }), !!heightField && /* @__PURE__ */ createElement(SugaredField, {
    field: heightField
  })),
  extractFileData: ({ objectUrl }) => {
    if (!heightField && !widthField) {
      return null;
    }
    return new Promise((resolve, reject) => {
      const image = new Image();
      image.addEventListener("load", () => {
        resolve(image);
      });
      image.addEventListener("error", (e) => {
        reject(e.message);
      });
      image.src = objectUrl;
    });
  },
  populateFields: ({ entity, extractedData }) => {
    entity.batchUpdates((getAccessor) => {
      widthField && getAccessor().getField(widthField).updateValue(extractedData.naturalWidth);
      heightField && getAccessor().getField(heightField).updateValue(extractedData.naturalHeight);
    });
  }
});
export { getImageFileDataExtractor };
//# sourceMappingURL=getImageFileDataExtractor.js.map
