"use strict";

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

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

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

var _reactDom = _interopRequireDefault(require("react-dom"));

var _reactScrollSync = require("react-scroll-sync");

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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 StyledPreviewContent = /*#__PURE__*/(0, _base.default)("div", {
  target: "e1x1aj6l0",
  label: "StyledPreviewContent"
})(process.env.NODE_ENV === "production" ? {
  name: "1pu5ell",
  styles: "width:calc(100% - min(864px, 50%));top:66px;right:0;position:absolute;height:calc(100% - 66px);overflow-y:auto"
} : {
  name: "1pu5ell",
  styles: "width:calc(100% - min(864px, 50%));top:66px;right:0;position:absolute;height:calc(100% - 66px);over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KFxuICAgICAgPFNjcm9sbFN5bmNQYW5lPlxuICAgICAgICA8U3R5bGVkUHJldmlld0NvbnRlbnQgY2xhc3NOYW1lPVwicHJldmlldy1jb250ZW50XCI+e2NoaWxkcmVufTwvU3R5bGVkUHJldmlld0NvbnRlbnQ+XG4gICAgICA8L1Njcm9sbFN5bmNQYW5lPixcbiAgICAgIGVsZW1lbnQsXG4gICAgICAncHJldmlldy1jb250ZW50J1xuICAgICk7XG4gIH0sIFtwcmV2aWV3Q29tcG9uZW50LCBwcmV2aWV3UHJvcHMsIGVsZW1lbnRdKTtcbn07XG5cbmV4cG9ydCBkZWZhdWx0IFByZXZpZXdDb250ZW50O1xuIl19 */",
  toString: _EMOTION_STRINGIFIED_CSS_ERROR__
});

const PreviewContent = _ref => {
  let {
    previewComponent,
    previewProps
  } = _ref;
  const element = (0, _react.useMemo)(() => document.getElementById('cms-root'), []);
  return (0, _react.useMemo)(() => {
    if (!element) {
      return null;
    }

    let children;

    if (!previewComponent) {
      children = null;
    } else if ( /*#__PURE__*/_react.default.isValidElement(previewComponent)) {
      children = /*#__PURE__*/_react.default.cloneElement(previewComponent, previewProps);
    } else {
      children = /*#__PURE__*/_react.default.createElement(previewComponent, previewProps);
    }

    return /*#__PURE__*/_reactDom.default.createPortal((0, _react2.jsx)(_reactScrollSync.ScrollSyncPane, null, (0, _react2.jsx)(StyledPreviewContent, {
      className: "preview-content"
    }, children)), element, 'preview-content');
  }, [previewComponent, previewProps, element]);
};

var _default = PreviewContent;
exports.default = _default;