import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { SugaredField } from "@contember/react-binding";
const getImageFileDataExtractor = ({
  heightField,
  widthField
}) => ({
  staticRender: () => /* @__PURE__ */ jsxDEV(Fragment, { children: [
    !!widthField && /* @__PURE__ */ jsxDEV(SugaredField, { field: widthField }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/fileDataExtractors/getImageFileDataExtractor.tsx",
      lineNumber: 16,
      columnNumber: 21
    }, void 0),
    !!heightField && /* @__PURE__ */ jsxDEV(SugaredField, { field: heightField }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/fileDataExtractors/getImageFileDataExtractor.tsx",
      lineNumber: 17,
      columnNumber: 22
    }, void 0)
  ] }, void 0, true, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/fileDataExtractors/getImageFileDataExtractor.tsx",
    lineNumber: 15,
    columnNumber: 3
  }, void 0),
  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
