"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

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

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

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

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

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

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/>.
 */
var CanvasRce =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(CanvasRce, _Component);

  function CanvasRce() {
    (0, _classCallCheck2.default)(this, CanvasRce);
    return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(CanvasRce).apply(this, arguments));
  }

  (0, _createClass2.default)(CanvasRce, [{
    key: "componentWillMount",
    value: function componentWillMount() {
      if (!this.props.skin) {
        _tinymceLightSkin.default.useCanvas();
      }

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

      this.normalizedProps = (0, _normalizeProps.default)(this.props.rceProps, _tinyRCE.default);

      _formatMessage.default.setup({
        locale: this.normalizedProps.language
      });
    }
  }, {
    key: "componentDidMount",
    value: function componentDidMount() {
      _bridge.default.renderEditor(this.rce);

      this.props.renderCallback && this.props.renderCallback(this.rce);
    }
  }, {
    key: "componentWillUpdate",
    value: function componentWillUpdate(nextProps) {
      if (this.props.rcePropsToggle !== nextProps.rcePropsToggle) {
        this.normalizedProps = (0, _normalizeProps.default)(nextProps.rceProps, _tinyRCE.default);
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      return _react.default.createElement(_RCEWrapper.default, Object.assign({}, this.normalizedProps, {
        ref: function ref(node) {
          return _this.rce = node;
        }
      }));
    }
  }]);
  CanvasRce.displayName = "CanvasRce";
  return CanvasRce;
}(_react.Component);

exports.default = CanvasRce;
CanvasRce.propTypes = {
  skin: _propTypes.default.object,
  rceProps: _propTypes.default.object,
  renderCallback: _propTypes.default.func,
  // rcePropsToggle forces the component to re-evaulate rceProps when changed
  // Without it, the component cannot recognize changes to editorOptions
  rcePropsToggle: _propTypes.default.bool
};