"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const reactBinding = require("@contember/react-binding");
const getVideoFileDataExtractor = ({
  heightField,
  widthField,
  durationField
}) => ({
  staticRender: () => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
    !!widthField && /* @__PURE__ */ jsxRuntime.jsx(reactBinding.SugaredField, { field: widthField }),
    !!heightField && /* @__PURE__ */ jsxRuntime.jsx(reactBinding.SugaredField, { field: heightField }),
    !!durationField && /* @__PURE__ */ jsxRuntime.jsx(reactBinding.SugaredField, { field: durationField })
  ] }),
  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);
    });
  }
});
exports.getVideoFileDataExtractor = getVideoFileDataExtractor;
//# sourceMappingURL=getVideoFileDataExtractor.cjs.map
