"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const reactBinding = require("@contember/react-binding");
const getAudioFileDataExtractor = ({
  durationField
}) => ({
  staticRender: () => !!durationField && /* @__PURE__ */ jsxRuntime.jsx(reactBinding.SugaredField, { field: durationField }),
  extractFileData: ({ objectUrl }) => {
    if (!durationField) {
      return null;
    }
    return new Promise((resolve, reject) => {
      const audio = document.createElement("audio");
      audio.addEventListener("canplay", () => {
        resolve(audio);
      });
      audio.addEventListener("error", () => {
        reject();
      });
      audio.src = objectUrl;
    });
  },
  populateFields: ({ entity, extractedData }) => {
    !!durationField && entity.getField(durationField).updateValue(extractedData.duration);
  }
});
exports.getAudioFileDataExtractor = getAudioFileDataExtractor;
//# sourceMappingURL=getAudioFileDataExtractor.cjs.map
