import _extends from "@babel/runtime/helpers/extends";
import React, { forwardRef, useEffect, useState, useImperativeHandle } from 'react';
import { Editor, Toolbar } from '@wangeditor/editor-for-react';
import { i18nChangeLanguage } from '@wangeditor/editor';
import '@wangeditor/editor/dist/css/style.css';
var RichEditor = function RichEditor(props, ref) {
  var editorConfig = props.editorConfig,
    defaultValue = props.defaultValue,
    style = props.style,
    __designMode = props.__designMode,
    language = props.language;
  var isDesignMode = __designMode === 'design';
  var _useState = useState(null),
    editor = _useState[0],
    setEditor = _useState[1];
  // 编辑器内容
  var _useState2 = useState(defaultValue),
    html = _useState2[0],
    setHtml = _useState2[1];

  // 工具栏配置
  var toolbarConfig = {};

  // 不支持动态刷新语言
  i18nChangeLanguage(language || 'zh-CN');

  // 及时销毁editor
  useEffect(function () {
    return function () {
      if (editor === null) return;
      editor.destroy();
      setEditor(null);
    };
  }, [editor]);
  useImperativeHandle(ref, function () {
    return {
      editor: editor
    };
  });
  return /*#__PURE__*/React.createElement("div", {
    ref: ref,
    style: _extends({}, style || {})
  }, /*#__PURE__*/React.createElement(Toolbar, {
    defaultConfig: toolbarConfig,
    mode: "default",
    editor: editor,
    style: {
      pointerEvents: isDesignMode ? 'none' : 'auto',
      borderBottom: '1px solid #ccc'
    }
  }), /*#__PURE__*/React.createElement(Editor, {
    defaultConfig: editorConfig // 默认配置
    ,
    onCreated: setEditor,
    mode: "default",
    onChange: function onChange(domEditor) {
      return setHtml(domEditor.getHtml());
    },
    value: html,
    style: {
      pointerEvents: isDesignMode ? 'none' : 'auto'
    }
  }));
};
var RefRichEditor = /*#__PURE__*/forwardRef(RichEditor);
RefRichEditor.displayName = 'RichEditor';
export default RefRichEditor;