import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { SugaredField } from "@contember/react-binding";
const getVideoFileDataExtractor = ({
  heightField,
  widthField,
  durationField
}) => ({
  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/getVideoFileDataExtractor.tsx",
      lineNumber: 18,
      columnNumber: 21
    }, void 0),
    !!heightField && /* @__PURE__ */ jsxDEV(SugaredField, { field: heightField }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/fileDataExtractors/getVideoFileDataExtractor.tsx",
      lineNumber: 19,
      columnNumber: 22
    }, void 0),
    !!durationField && /* @__PURE__ */ jsxDEV(SugaredField, { field: durationField }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/fileDataExtractors/getVideoFileDataExtractor.tsx",
      lineNumber: 20,
      columnNumber: 24
    }, void 0)
  ] }, void 0, true, {
    fileName: "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/fileDataExtractors/getVideoFileDataExtractor.tsx",
    lineNumber: 17,
    columnNumber: 3
  }, void 0),
  extractFileData: ({ objectUrl }) => {
    if (!durationField && !heightField && !widthField) {
      return null;
    }
    return new Promise((resolve, reject) => {
      const video = document.createElement("video");
      video.addEventListener("canplay", () => {
        resolve(video);
      });
      video.addEventListener("error", () => {
        reject();
      });
      video.src = objectUrl;
    });
  },
  populateFields: ({ entity, extractedData }) => {
    entity.batchUpdates((getAccessor) => {
      widthField && getAccessor().getField(widthField).updateValue(extractedData.videoWidth);
      heightField && getAccessor().getField(heightField).updateValue(extractedData.videoHeight);
      durationField && getAccessor().getField(durationField).updateValue(extractedData.duration);
    });
  }
});
export {
  getVideoFileDataExtractor
};
//# sourceMappingURL=getVideoFileDataExtractor.js.map
