'use strict';

var chunkMVQKV5BJ_cjs = require('./chunk-MVQKV5BJ.cjs');
var classnames = require('classnames');
var React2 = require('react');
var icons = require('@blueprintjs/icons');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var classnames__default = /*#__PURE__*/_interopDefault(classnames);
var React2__default = /*#__PURE__*/_interopDefault(React2);

// src/video-viewer/BaseVideoViewer.module.css
var BaseVideoViewer_default = {};

// src/video-viewer/BaseVideoViewer.tsx
function BaseVideoViewer({
  src,
  mimeType,
  className,
  onError
}) {
  const rootClassName = classnames__default.default(BaseVideoViewer_default.container, className);
  return /* @__PURE__ */ React2__default.default.createElement("div", {
    className: rootClassName
  }, /* @__PURE__ */ React2__default.default.createElement("video", {
    className: BaseVideoViewer_default.video,
    controls: true,
    onError
  }, /* @__PURE__ */ React2__default.default.createElement("source", {
    src,
    type: mimeType
  })));
}
function _extends() {
  return _extends = Object.assign ? Object.assign.bind() : function(n) {
    for (var e = 1; e < arguments.length; e++) {
      var t = arguments[e];
      for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
    }
    return n;
  }, _extends.apply(null, arguments);
}
var transformToObjectUrl = async (response) => {
  const blob = await response.blob();
  return URL.createObjectURL(blob);
};
var cleanupObjectUrl = (url) => {
  URL.revokeObjectURL(url);
};
function VideoViewer({
  media,
  className,
  ...videoViewerProps
}) {
  const {
    data: src,
    loading,
    error
  } = chunkMVQKV5BJ_cjs.useMediaContents(media, transformToObjectUrl, cleanupObjectUrl);
  const mimeType = React2.useMemo(() => videoViewerProps.mimeType ?? media.getMediaReference().mimeType, [videoViewerProps.mimeType, media]);
  const rootClassName = classnames__default.default(BaseVideoViewer_default.container, className);
  return /* @__PURE__ */ React2__default.default.createElement("div", {
    className: rootClassName
  }, loading && /* @__PURE__ */ React2__default.default.createElement("div", {
    className: BaseVideoViewer_default.loadingContainer
  }, /* @__PURE__ */ React2__default.default.createElement(icons.Spin, {
    className: BaseVideoViewer_default.spinnerIcon
  }), "Loading\u2026"), error != null && /* @__PURE__ */ React2__default.default.createElement("div", {
    className: BaseVideoViewer_default.errorContainer
  }, /* @__PURE__ */ React2__default.default.createElement(icons.Error, {
    className: BaseVideoViewer_default.errorIcon
  }), "Failed to load video: ", error.message), src != null && /* @__PURE__ */ React2__default.default.createElement(BaseVideoViewer, _extends({
    src,
    mimeType
  }, videoViewerProps)));
}

exports.BaseVideoViewer = BaseVideoViewer;
exports.VideoViewer = VideoViewer;
//# sourceMappingURL=chunk-KHMOMROL.cjs.map
//# sourceMappingURL=chunk-KHMOMROL.cjs.map