import React, { Component } from 'react';
import './index.less';

export default class Editor extends Component {
  componentWillMount() {
    const { onChange } = this.props;
    setTimeout(() => {
      const editor = CKEDITOR.replace('editor', {
        skin: 'moono',
        toolbarGroups: [{ name: 'clipboard', groups: ['undo', 'clipboard'] }],
        removePlugins: 'pastetext,pastefromword',
        language: 'en',
      });
      editor.on('change', () => {
        if (onChange) onChange(editor.getData());
      });
    }, 1);
  }

  render() {
    return <textarea name="editor" />;
  }
}
