/*
 * @Description: 
 * @Author: tangjiang
 * @Github: 
 * @Date: 2019-12-01 10:18:35
 * @LastEditors  : tangjiang
 * @LastEditTime : 2019-12-27 19:33:50
 */
import './index.scss';
import React from 'react';
import { connect } from 'react-redux';
import MyMonacoEditor from '../../components/myMonacoEditor';
import actions from '../../../../redux/actions';

function RightPane(props) {

  const { code, language, saveOjFormCode } = props;

  const handleCodeChange = (updateCode) => {
    saveOjFormCode(updateCode);
  }
  return (
    <div className={'right_pane_code_wrap'}>
      {language ?
        <MyMonacoEditor
          language={language}
          code={code}
          onCodeChange={handleCodeChange} /> : null
      }


    </div>
  )
}

const mapStateToProps = (state) => {
  const { ojForm, testCases, code, identifier, showCode } = state.ojFormReducer;
  return {
    code,
    showCode,
    identifier,
    language: ojForm.language,
    input: (testCases[0] && testCases[0].input) || '',
  }
};
const mapDispatchToProps = (dispatch) => ({
  // 保存提交的代码值
  saveOjFormCode: (value) => dispatch(actions.saveOjFormCode(value)),
});
export default connect(
  mapStateToProps,
  mapDispatchToProps
)(RightPane);
