function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? Object(arguments[i]) : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys.push.apply(ownKeys, Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/* eslint-disable consistent-return */
import React from 'react';
import { componentMap } from '../component-types';
/**
 * @class Renderer 页面预览器，外部工程使用此类来渲染出页面。
 */

var Renderer = function Renderer(props) {
  var pageData = props.pageData,
      device = props.device,
      MParams = props.MParams;
  window.MParams = MParams;
  return /*#__PURE__*/React.createElement("div", {
    className: "render_wrap"
  }, pageData && pageData.childNodes && pageData.childNodes.map(function (nodeData) {
    var Clazz = componentMap[nodeData.type];

    if (!Clazz) {
      console.error("[MagicBox] Can not find type ".concat(nodeData.type));
      return;
    }

    var newInstanceProps = _objectSpread({}, nodeData, {
      nodeData: nodeData,
      mode: 'renderer',
      terminalType: device
    });

    return /*#__PURE__*/React.createElement("div", {
      key: nodeData.id
    }, React.createElement(Clazz, _objectSpread({}, newInstanceProps), null));
  }));
};

Renderer.defaultProps = {
  pageData: {},
  device: 'pc',
  MParams: {}
};
export default Renderer;