"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _base = _interopRequireDefault(require("@emotion/styled/base"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _immutable = require("immutable");

var _ui = require("../../ui");

var _react2 = require("@emotion/react");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }

const StyledImage = /*#__PURE__*/(0, _base.default)(_ref => {
  let {
    src
  } = _ref;
  return (0, _react2.jsx)("img", {
    src: src || '',
    role: "presentation"
  });
}, {
  target: "e124kn760",
  label: "StyledImage"
})(process.env.NODE_ENV === "production" ? {
  name: "waguu7",
  styles: "display:block;max-width:100%;height:auto"
} : {
  name: "waguu7",
  styles: "display:block;max-width:100%;height:auto",
  map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy93aWRnZXRzL2ltYWdlL0ltYWdlUHJldmlldy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFPb0YiLCJmaWxlIjoiLi4vLi4vLi4vLi4vc3JjL3dpZGdldHMvaW1hZ2UvSW1hZ2VQcmV2aWV3LmpzIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IFJlYWN0IGZyb20gJ3JlYWN0JztcbmltcG9ydCBQcm9wVHlwZXMgZnJvbSAncHJvcC10eXBlcyc7XG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCc7XG5pbXBvcnQgeyBMaXN0IH0gZnJvbSAnaW1tdXRhYmxlJztcblxuaW1wb3J0IHsgV2lkZ2V0UHJldmlld0NvbnRhaW5lciB9IGZyb20gJy4uLy4uL3VpJztcblxuY29uc3Q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LmZ1bmMuaXNSZXF1aXJlZCxcbiAgdmFsdWU6IFByb3BUeXBlcy5ub2RlLFxufTtcblxuZXhwb3J0IGRlZmF1bHQgSW1hZ2VQcmV2aWV3O1xuIl19 */",
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});

function StyledImageAsset(_ref2) {
  let {
    getAsset,
    value,
    field
  } = _ref2;
  return (0, _react2.jsx)(StyledImage, {
    src: getAsset(value, field)
  });
}

function ImagePreviewContent(props) {
  const {
    value,
    getAsset,
    field
  } = props;

  if (Array.isArray(value) || _immutable.List.isList(value)) {
    return value.map(val => (0, _react2.jsx)(StyledImageAsset, {
      key: val,
      value: val,
      getAsset: getAsset,
      field: field
    }));
  }

  return (0, _react2.jsx)(StyledImageAsset, props);
}

function ImagePreview(props) {
  return (0, _react2.jsx)(_ui.WidgetPreviewContainer, null, props.value ? (0, _react2.jsx)(ImagePreviewContent, props) : null);
}

ImagePreview.propTypes = {
  getAsset: _propTypes.default.func.isRequired,
  value: _propTypes.default.node
};
var _default = ImagePreview;
exports.default = _default;