"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 _reactRedux = require("react-redux");

var _Sidebar = _interopRequireDefault(require("./containers/Sidebar"));

var _configureStore = _interopRequireDefault(require("./store/configureStore"));

var _facade = _interopRequireDefault(require("./facade"));

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

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

/*
 * 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) {
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var renderCallback = arguments.length > 2 ? arguments[2] : undefined;
  // create a new store for the Provider to use (it will then be passed on to
  // any container components under the Provider)
  var store = (0, _configureStore.default)(props); // normalize props

  props = (0, _normalizeProps.default)(props); // render the sidebar, inside a Provider, to the target element

  _bridge.default.editorRendered.then(function () {
    (0, _reactDom.render)(_react.default.createElement(_reactRedux.Provider, {
      store: store
    }, _react.default.createElement(_Sidebar.default, {
      onLinkClick: props.onLinkClick,
      onImageEmbed: props.onImageEmbed,
      canUploadFiles: props.canUploadFiles,
      filesTabDisabled: props.filesTabDisabled
    })), target);

    if (renderCallback) {
      // capture the store that's driving the component in a facade that
      // exposes a public API to the caller. then pass it back
      renderCallback(new _facade.default(store));
    }
  });
}