"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 _reactImmutableProptypes = _interopRequireDefault(require("react-immutable-proptypes"));

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)."; }

function isVisible(field) {
  return field.get('widget') !== 'hidden';
}

const PreviewContainer = /*#__PURE__*/(0, _base.default)("div", {
  target: "ep41e7x0",
  label: "PreviewContainer"
})(process.env.NODE_ENV === "production" ? {
  name: "1dhnsqy",
  styles: "overflow-y:auto;height:100%;padding:24px;box-sizing:border-box;font-family:Roboto,'Helvetica Neue',HelveticaNeue,Helvetica,Arial,sans-serif"
} : {
  name: "1dhnsqy",
  styles: "overflow-y:auto;height:100%;padding:24px;box-sizing:border-box;font-family:Roboto,'Helvetica Neue',HelveticaNeue,Helvetica,Arial,sans-serif",
  map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9jb21wb25lbnRzL0VkaXRvci9FZGl0b3JQcmV2aWV3UGFuZS9FZGl0b3JQcmV2aWV3LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQVNtQyIsImZpbGUiOiIuLi8uLi8uLi8uLi8uLi9zcmMvY29tcG9uZW50cy9FZGl0b3IvRWRpdG9yUHJldmlld1BhbmUvRWRpdG9yUHJldmlldy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBSZWFjdCBmcm9tICdyZWFjdCc7XG5pbXBvcnQgUHJvcFR5cGVzIGZyb20gJ3Byb3AtdHlwZXMnO1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5nZXQoJ25hbWUnKX0+e3dpZGdldEZvcihmaWVsZC5nZXQoJ25hbWUnKSl9PC9kaXY+XG4gICAgICAgICAgKSl9XG4gICAgICAgIDwvUHJldmlld0NvbnRhaW5lcj5cbiAgICApO1xuICB9XG59XG5cblByZXZpZXcucHJvcFR5cGVzID0ge1xuICBjb2xsZWN0aW9uOiBJbW11dGFibGVQcm9wVHlwZXMubWFwLmlzUmVxdWlyZWQsXG4gIGVudHJ5OiBJbW11dGFibGVQcm9wVHlwZXMubWFwLmlzUmVxdWlyZWQsXG4gIGZpZWxkczogSW1tdXRhYmxlUHJvcFR5cGVzLmxpc3QuaXNSZXF1aXJlZCxcbiAgZ2V0QXNzZXQ6IFByb3BUeXBlcy5mdW5jLmlzUmVxdWlyZWQsXG4gIHdpZGdldEZvcjogUHJvcFR5cGVzLmZ1bmMuaXNSZXF1aXJlZCxcbn07XG4iXX0= */",
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});
/**
 * Use a stateful component so that child components can effectively utilize
 * `shouldComponentUpdate`.
 */

class Preview extends _react.default.Component {
  render() {
    const {
      collection,
      fields,
      widgetFor
    } = this.props;

    if (!collection || !fields) {
      return null;
    }

    return (0, _react2.jsx)(PreviewContainer, null, fields.filter(isVisible).map(field => (0, _react2.jsx)("div", {
      key: field.get('name')
    }, widgetFor(field.get('name')))));
  }

}

exports.default = Preview;
Preview.propTypes = {
  collection: _reactImmutableProptypes.default.map.isRequired,
  entry: _reactImmutableProptypes.default.map.isRequired,
  fields: _reactImmutableProptypes.default.list.isRequired,
  getAsset: _propTypes.default.func.isRequired,
  widgetFor: _propTypes.default.func.isRequired
};