"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 FileLink = /*#__PURE__*/(0, _base.default)(_ref => {
  let {
    href,
    path
  } = _ref;
  return (0, _react2.jsx)("a", {
    href: href,
    rel: "noopener noreferrer",
    target: "_blank"
  }, path);
}, {
  target: "e9ulycf0",
  label: "FileLink"
})(process.env.NODE_ENV === "production" ? {
  name: "4zleql",
  styles: "display:block"
} : {
  name: "4zleql",
  styles: "display:block",
  map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy93aWRnZXRzL2ZpbGUvRmlsZVByZXZpZXcuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBV0UiLCJmaWxlIjoiLi4vLi4vLi4vLi4vc3JjL3dpZGdldHMvZmlsZS9GaWxlUHJldmlldy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBSZWFjdCBmcm9tICdyZWFjdCc7XG5pbXBvcnQgUHJvcFR5cGVzIGZyb20gJ3Byb3AtdHlwZXMnO1xuaW1wb3J0IHN0eWxlZCBmcm9tICdAZW1vdGlvbi9zdHlsZWQnO1xuaW1wb3J0IHsgTGlzdCB9IGZyb20gJ2ltbXV0YWJsZSc7XG5cbmltcG9ydCB7IFdpZGdldFByZXZpZXdDb250YWluZXIgfSBmcm9tICcuLi8uLi91aSc7XG5cbmNvbnN0IEZpbGVMaW5rID0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dDb250YWluZXI+XG4gICk7XG59XG5cbkZpbGVQcmV2aWV3LnByb3BUeXBlcyA9IHtcbiAgZ2V0QXNzZXQ6IFByb3BUeXBlcy5mdW5jLmlzUmVxdWlyZWQsXG4gIHZhbHVlOiBQcm9wVHlwZXMubm9kZSxcbn07XG5cbmV4cG9ydCBkZWZhdWx0IEZpbGVQcmV2aWV3O1xuIl19 */",
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});

function FileLinkList(_ref2) {
  let {
    values,
    getAsset,
    field
  } = _ref2;
  return (0, _react2.jsx)("div", null, values.map(value => (0, _react2.jsx)(FileLink, {
    key: value,
    path: value,
    href: getAsset(value, field)
  })));
}

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

  if (Array.isArray(value) || _immutable.List.isList(value)) {
    return (0, _react2.jsx)(FileLinkList, {
      values: value,
      getAsset: getAsset,
      field: field
    });
  }

  return (0, _react2.jsx)(FileLink, {
    key: value,
    path: value,
    href: getAsset(value, field)
  });
}

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

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