import React, { Component } from "react";
import Editor from "react-monaco-editor";
import UserSubmitComponent from "./UserSubmitComponent";

import "./index.css";
import "./editor.css";

class m_editor extends Component {
  constructor(props) {
    super(props);
    this.state = {
      editorValue: this.props.content,
    };
  }
  changeEditor = (editorValue) => {
    this.setState({
      editorValue,
    });
  };

  render() {
    const { editorValue } = this.state;
    const { readOnly, editorType, language } = this.props;
    const editor_options = {
      lineNumbers: "on",
      wordWrap: true, //强制换行
      selectOnLineNumbers: true,
      lineHeight: 24,
      renderLineHighlight: "line",
      revealHorizontalRightPadding: 5,
      placeholder:"请输入内容",
      readOnly: readOnly,
      cursorStyle: readOnly ? "underline-thin" : "line",
      folding: true,
      foldingStrategy: "indentation", // 代码可分小段折叠
      automaticLayout: true, // 自适应布局
      // overviewRulerBorder: false, // 不要滚动条的边框
      // scrollBeyondLastLine: false, // 取消代码后面一大段空白
      minimap: {
        // 不要小地图
        enabled: false,
      },
    };
    return (
      <React.Fragment>
        <div>
          <div className="branchTable">
            <Editor
              height="400px"
              language={language ? language : "plaintext"}
              theme={"vs-grey"}
              placeholder="请输入内容"
              value={editorValue}
              options={editor_options}
              onChange={this.changeEditor}
              editorWillMount={this.editorWillMount}
            />
          </div>

          {!readOnly && (
            <UserSubmitComponent
              {...this.props}
              {...this.state}
              filepath={`${this.props.filepath}`}
              content={editorValue}
              editor_type={editorType}
            ></UserSubmitComponent>
          )}
        </div>
      </React.Fragment>
    );
  }
}
export default m_editor;
