import React from 'react';
import {inject, observer} from "mobx-react";
import {Button} from 'antd';
import {WeaLocaleProvider, WeaRightMenu, WeaDialog, WeaFormItem, WeaCodeMirror, WeaSearchGroup} from "ecCom";
import {GeneralTitleColor, defaultBtns} from "../../util/IntegrationUtil";

const {getLabel} = WeaLocaleProvider;

@inject("oauth2Store")
@observer
export default class TestMessage extends React.Component {
  componentWillUnmount() {
    this.props.oauth2Store.setState({testMessage: ""});
  }

  getRightMenu = () => {
    return defaultBtns.defaultCloseBtns && defaultBtns.defaultCloseBtns.map(v => {
      return {
        ...v,
        onClick: () => this.props.oauth2Store.setState({testDialogVisible: false})
      } 
    })
  }

  getBtns = () => {
    return defaultBtns.defaultCloseBtns && defaultBtns.defaultCloseBtns.map(v => <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@xxznph@integrationAouth2TestButton${v.key}`} key={v.key} type={v.type} onClick={() => this.props.oauth2Store.setState({testDialogVisible: false})}>{v.content}</Button>); 
  }

  render() {
    const {oauth2Store} = this.props;
    const {status: {testDialogVisible, testMessage, testType}} = oauth2Store;

    return <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@mtkms1`}
      visible={testDialogVisible}
      title={getLabel('25496','测试')}
      onCancel={()=> oauth2Store.setState({testDialogVisible: false})}
      style={{width: 800, height: 400}}
      hasScroll
      moduleName={GeneralTitleColor.moduleName}
      buttons={this.getBtns()}
      moreBtn={{
        datas: this.getRightMenu(),
        collectParams: []
      }}
    >
      <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@0xhoo6`}
        datas={this.getRightMenu()}
        collectParams={{}}
      >
        <WeaCodeMirror key={testType} ecId={`${this && this.props && this.props.ecId || ''}_WeaCodeMirror@1yjf1i`} viewAttr={1} value={testMessage} width={800} height={400} onChange={() => {}} />
      </WeaRightMenu>
    </WeaDialog>
  }
}