'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/images/image-viewer/BaseImageViewer.module.css
var BaseImageViewer_default = {};

// src/images/image-viewer/BaseImageViewer.tsx
function BaseImageViewer({
  src,
  alt,
  className,
  onError
}) {
  const rootClassName = classnames__default.default(BaseImageViewer_default.container, className);
  return /* @__PURE__ */ React2__default.default.createElement("div", {
    className: rootClassName
  }, /* @__PURE__ */ React2__default.default.createElement("img", {
    className: BaseImageViewer_default.image,
    src,
    alt: alt ?? "",
    onError
  }));
}
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 ImageViewer({
  media,
  className,
  ...imageViewerProps
}) {
  const {
    data: src,
    loading,
    error
  } = chunkMVQKV5BJ_cjs.useMediaContents(media, transformToObjectUrl, cleanupObjectUrl);
  const rootClassName = classnames__default.default(BaseImageViewer_default.container, className);
  return /* @__PURE__ */ React2__default.default.createElement("div", {
    className: rootClassName
  }, loading && /* @__PURE__ */ React2__default.default.createElement("div", {
    className: BaseImageViewer_default.loadingContainer
  }, /* @__PURE__ */ React2__default.default.createElement(icons.Spin, {
    className: BaseImageViewer_default.spinnerIcon
  }), "Loading\u2026"), error != null && /* @__PURE__ */ React2__default.default.createElement("div", {
    className: BaseImageViewer_default.errorContainer
  }, /* @__PURE__ */ React2__default.default.createElement(icons.Error, {
    className: BaseImageViewer_default.errorIcon
  }), "Failed to load image: ", error.message), src != null && /* @__PURE__ */ React2__default.default.createElement(BaseImageViewer, _extends({
    src
  }, imageViewerProps)));
}

exports.BaseImageViewer = BaseImageViewer;
exports.ImageViewer = ImageViewer;
//# sourceMappingURL=chunk-VOROB7KJ.cjs.map
//# sourceMappingURL=chunk-VOROB7KJ.cjs.map