"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

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

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

var _RCEWrapper = _interopRequireDefault(require("./RCEWrapper"));

var _tinyRCE = _interopRequireDefault(require("./tinyRCE"));

var _normalizeProps = _interopRequireDefault(require("./normalizeProps"));

var _formatMessage = _interopRequireDefault(require("../format-message"));

var _bridge = _interopRequireDefault(require("../bridge"));

var _tinymceLightSkin = _interopRequireDefault(require("tinymce-light-skin"));

/*
 * Copyright (C) 2018 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */
function renderIntoDiv(target, props, renderCallback) {
  if (!props.skin) {
    _tinymceLightSkin.default.useCanvas();
  } // prevent tinymce from loading the theme


  _tinyRCE.default.DOM.loadCSS = function () {}; // normalize props


  props = (0, _normalizeProps.default)(props, _tinyRCE.default);

  _formatMessage.default.setup({
    locale: props.language
  }); // render the editor to the target element


  var renderedComponent = (0, _reactDom.render)(_react.default.createElement(_RCEWrapper.default, Object.assign({}, props, {
    handleUnmount: function handleUnmount() {
      return (0, _reactDom.unmountComponentAtNode)(target);
    }
  })), target); // connect the editor to the event bridge if no editor is currently active

  _bridge.default.renderEditor(renderedComponent); // pass it back


  renderCallback && renderCallback(renderedComponent);
}