import {
	inject,
	observer,
} from 'mobx-react'
import {
	toJS
} from 'mobx'
import {
	WeaRightMenu,
	WeaSearchGroup,
} from 'ecCom'
import {
	Spin,
} from 'antd'
import {
	i18n
} from '../../public/i18n';

import FormInfo from './FormInfo';
import RichText from './RichText';

@inject('hrmContractMaintain')
@observer
export default class DialogContent extends React.Component {
	constructor(props) {
		super(props);
	}

	componentDidMount() {
		this.props.hrmContractMaintain.getFormInfo();
	}


	getDropMenuDatas = () => {
		const {
			hrmContractMaintain
		} = this.props, {
			formInfo
		} = hrmContractMaintain, {
			loading
		} = formInfo;

		const menu = [{
			key: '0',
			icon: <i className='icon-coms-Preservation' />,
			content: i18n.button.save(),
			disabled: loading,
		}];

		return menu
	}

	handleMenuClick = (key) => {
		this[key] && this[key]();
	}

	save = () => {
		const {
			hrmContractMaintain
		} = this.props, {
			save
		} = hrmContractMaintain;

		save();
	}

	render() {
		const {
			hrmContractMaintain
		} = this.props, {
			formInfo
		} = hrmContractMaintain, {
			loading
		} = formInfo;

		if (loading) {
			return (
				<div className='hrm-loading-center-small'>
					<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@82w0l3`} spinning={loading}></Spin>
				</div>
			)
		} else {
			return (
				<WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@xysh4m`} datas={this.getDropMenuDatas()} onClick={ key => this.handleMenuClick(key)}>
					<div className='hrm-searchp-form'>
						<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@3zgwoh`} 
							title={i18n.label.basicInfo()} 
							children={<FormInfo ecId={`${this && this.props && this.props.ecId || ''}_FormInfo@wfk5v4`} />} 
							showGroup={true} 
						/>
					</div>
					<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@k7s641`} 
						title={i18n.label.contractContent()} 
						children={<RichText ecId={`${this && this.props && this.props.ecId || ''}_RichText@hed5zo`} />} 
						showGroup={true} 
					/>
	          	</WeaRightMenu>
			)
		}
	}
}