'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _server = require('react-dom/server');

var _server2 = _interopRequireDefault(_server);

var _utils = require('./utils');

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

function mounter(layoutClass, regions, options) {
  var el = _react2.default.createElement(layoutClass, regions);
  var elHtml = _server2.default.renderToString(el);

  var rootId = options.rootId;
  var rootProps = options.rootProps;

  var rootNodeHtml = (0, _utils.buildRootNode)(rootId, rootProps);
  var html = rootNodeHtml.replace('</div>', elHtml + '</div>');

  if (typeof Package === 'undefined') {
    var error = 'Server side mounting in only available with Meteor.';
    throw new Error(error);
  }

  if (!Package['kadira:flow-router-ssr']) {
    var _error = 'FlowRouter SSR is required to mount components in the server.';
    throw new Error(_error);
  }

  var FlowRouter = Package['kadira:flow-router-ssr'].FlowRouter;
  var ssrContext = FlowRouter.ssrContext.get();
  ssrContext.setHtml(html);
} /* global Package */