"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.InlineImageCard = void 0;
var _react = require("react");
var _react2 = require("@emotion/react");
var _mediaCommon = require("@atlaskit/media-common");
var _mediaFilePreview = require("@atlaskit/media-file-preview");
var _mediaUi = require("@atlaskit/media-ui");
var _loadingView = require("./views/loading-view");
/**
 * @jsxRuntime classic
 * @jsx jsx
 */

// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766

var InlineImageCard = exports.InlineImageCard = function InlineImageCard(_ref) {
  var dimensions = _ref.dimensions,
    identifier = _ref.identifier,
    renderError = _ref.renderError,
    alt = _ref.alt,
    isLazy = _ref.isLazy,
    ssr = _ref.ssr,
    crop = _ref.crop,
    stretch = _ref.stretch;
  // Generate unique traceId for file
  var traceContext = (0, _react.useMemo)(function () {
    return {
      traceId: (0, _mediaCommon.getRandomHex)(8)
    };
  }, []);

  // Ignored via go/ees007
  // eslint-disable-next-line @atlaskit/editor/enforce-todo-comment-format
  // TODO do we need to handle nonCriticalError
  var _useFilePreview = (0, _mediaFilePreview.useFilePreview)({
      identifier: identifier,
      ssr: ssr,
      dimensions: dimensions,
      traceContext: traceContext
    }),
    preview = _useFilePreview.preview,
    previewError = _useFilePreview.error,
    onImageError = _useFilePreview.onImageError,
    _onImageLoad = _useFilePreview.onImageLoad,
    getSsrScriptProps = _useFilePreview.getSsrScriptProps,
    copyNodeRef = _useFilePreview.copyNodeRef;
  if (previewError) {
    return renderError({
      error: previewError
    });
  }
  if (!preview) {
    return (0, _react2.jsx)(_loadingView.InlineImageCardLoadingView, null);
  }
  return (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)(_mediaUi.MediaImage, {
    dataURI: preview.dataURI,
    alt: alt,
    previewOrientation: preview.orientation,
    onImageLoad: function onImageLoad() {
      _onImageLoad(preview);
    },
    onImageError: onImageError,
    loading: isLazy ? 'lazy' : undefined,
    forceSyncDisplay: !!ssr,
    crop: crop,
    stretch: stretch,
    ref: copyNodeRef
  }), getSsrScriptProps &&
  // eslint-disable-next-line react/jsx-props-no-spreading
  (0, _react2.jsx)("script", getSsrScriptProps()));
};