import { createElement } from "react";
import { SugaredField } from "@contember/binding";
const getAudioFileDataExtractor = ({
  durationField
}) => ({
  staticRender: () => !!durationField && /* @__PURE__ */ createElement(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);
  }
});
export { getAudioFileDataExtractor };
//# sourceMappingURL=getAudioFileDataExtractor.js.map
