import { SugaredField } from "@contember/binding";
import { jsxDEV } from "react/jsx-dev-runtime";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/upload/fileDataExtractors/getAudioFileDataExtractor.tsx";
const getAudioFileDataExtractor = ({
  durationField
}) => ({
  staticRender: () => !!durationField && /* @__PURE__ */ jsxDEV(SugaredField, {
    field: durationField
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 12,
    columnNumber: 41
  }, void 0),
  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
