"use strict";

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

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

var _componentTypes = require("../../constants/component-types");

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

var __assign = void 0 && (void 0).__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};
/* eslint-disable consistent-return */


var setDesignConfig = function setDesignConfig(props) {
  var config = props.config,
      device = props.device,
      isShop = props.isShop;
  window.magicDesign = __assign({
    pageBackground: '#f2f2f2',
    compSpacing: '16',
    mode: 'renderer',
    device: device,
    isShop: isShop
  }, config);
};
/**
 * @class Renderer 页面预览器，外部工程使用此类来渲染出页面。
 */


var Renderer = function Renderer(props) {
  var pageData = props.pageData;
  setDesignConfig(props);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "render_wrap",
    magic_design: "",
    style: {
      background: window.magicDesign.pageBackground
    }
  }, pageData && pageData.childNodes && pageData.childNodes.map(function (nodeData) {
    var Clazz = _componentTypes.componentMap[nodeData.type];

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

    var newInstanceProps = __assign(__assign({}, nodeData), {
      nodeData: nodeData
    });

    return /*#__PURE__*/_react["default"].createElement("div", {
      key: nodeData.id
    }, /*#__PURE__*/_react["default"].createElement(Clazz, __assign({}, newInstanceProps), null));
  }));
};

Renderer.defaultProps = {
  pageData: {},
  device: 'pc',
  config: {}
};
var _default = Renderer;
exports["default"] = _default;