"use strict";

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

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

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

var _sanitizeEditorOptions = _interopRequireDefault(require("./sanitizeEditorOptions"));

var _wrapInitCb = _interopRequireDefault(require("./wrapInitCb"));

var _normalizeLocale = _interopRequireDefault(require("./normalizeLocale"));

var _editorLanguage = _interopRequireDefault(require("./editorLanguage"));

var _tinymceLightSkin = 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 _default(props, tinymce, MutationObserver) {
  var initialEditorOptions = props.editorOptions(tinymce),
      sanitizedEditorOptions = (0, _sanitizeEditorOptions.default)(initialEditorOptions),
      editorOptions = (0, _wrapInitCb.default)(props.mirroredAttrs, sanitizedEditorOptions, MutationObserver); // propagate localization prop to appropriate parameter/value on the
  // editor configuration

  props.language = (0, _normalizeLocale.default)(props.language);
  var language = (0, _editorLanguage.default)(props.language);

  if (language !== undefined) {
    editorOptions.language = language;
    editorOptions.language_url = "none";
  } // needed so brandable_css (which only exists in canvas) can load


  if (props.editorOptions.content_css) {
    editorOptions.content_css = window.location.origin + props.editorOptions.content_css;
  }

  editorOptions.skin = false;
  editorOptions.content_style = _tinymceLightSkin.contentStyle;
  editorOptions.branding = false;
  return (0, _objectSpread2.default)({}, props, {
    // enforced values, in addition to props and cannot be overridden by
    // props
    editorOptions: editorOptions,
    tinymce: tinymce
  });
}