"use strict";

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

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

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

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

var _reactImmutableProptypes = _interopRequireDefault(require("react-immutable-proptypes"));

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

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

const PreviewContainer = (0, _styledBase.default)("div", {
  target: "eu8frl10",
  label: "PreviewContainer"
})(process.env.NODE_ENV === "production" ? {
  name: "1gj2677",
  styles: "font-family:Roboto,'Helvetica Neue',HelveticaNeue,Helvetica,Arial,sans-serif;"
} : {
  name: "1gj2677",
  styles: "font-family:Roboto,'Helvetica Neue',HelveticaNeue,Helvetica,Arial,sans-serif;",
  map: "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3NyYy9jb21wb25lbnRzL0VkaXRvci9FZGl0b3JQcmV2aWV3UGFuZS9FZGl0b3JQcmV2aWV3LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQVNtQyIsImZpbGUiOiIuLi8uLi8uLi8uLi8uLi9zcmMvY29tcG9uZW50cy9FZGl0b3IvRWRpdG9yUHJldmlld1BhbmUvRWRpdG9yUHJldmlldy5qcyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCBSZWFjdCBmcm9tICdyZWFjdCc7XG5pbXBvcnQgUHJvcFR5cGVzIGZyb20gJ3Byb3AtdHlwZXMnO1xuaW1wb3J0IEltbXV0YWJsZVByb3BUeXBlcyBmcm9tICdyZWFjdC1pbW11dGFibGUtcHJvcHR5cGVzJztcbmltcG9ydCBzdHlsZWQgZnJvbSAnQGVtb3Rpb24vc3R5bGVkJztcblxuZnVuY3Rpb24gaXNWaXNpYmxlKGZpZWxkKSB7XG4gIHJldHVybiBmaWVsZC5nZXQ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W1tdXRhYmxlUHJvcFR5cGVzLmxpc3QuaXNSZXF1aXJlZCxcbiAgZ2V0QXNzZXQ6IFByb3BUeXBlcy5mdW5jLmlzUmVxdWlyZWQsXG4gIHdpZGdldEZvcjogUHJvcFR5cGVzLmZ1bmMuaXNSZXF1aXJlZCxcbn07XG4iXX0= */"
});
/**
 * 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 _react.default.createElement(PreviewContainer, null, fields.filter(isVisible).map(field => _react.default.createElement("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
};