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

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

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

	componentWillUnmount() {
		this.props.hrmRpManage.refreshFormInfo();
	}

	getForm = () => {
		const {
			hrmRpManage
		} = this.props, {
			formInfo,
		} = hrmRpManage, {
			form,
			conditions,
		} = formInfo, {
			isFormInit,
		} = form;

		let arr = [];
		isFormInit && conditions.map(c => {
			c.items.map((field, index) => {
				arr.push(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@h1wj99@${index}`}
                            label={`${field.label}`}
                            labelCol={{span: 6, offset: 2}}
                            wrapperCol={{span: 15}}
                            error={form.getError(field)}
                            tipPosition="bottom"
                        >
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@no9qwl@${index}`} fieldConfig={field} form={form} formParams={form.getFormParams()} onChange={cb => this.handleChange(cb)}/>
                        </WeaFormItem>)
			})
		})
		return <div className='wea-form-item-group'>{arr}</div>
	}

	handleChange = (cb) => {}

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

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

		return menu
	}

	handleMenuClick = (key) => {
		const {
			hrmRpManage,
		} = this.props, {
			save,
		} = hrmRpManage;

		key == '0' && save();
	}

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

		return (<div style={{height: '100%'}}>
					{loading ? 	<div style={{textAlign: 'center', paddingTop: 150}}>
									<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@x9zpdx`} spinning={loading}></Spin>
							   	</div>
							 : 	<WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@485qoq`} datas={this.getDropMenuDatas()} onClick={ key => this.handleMenuClick(key)}>
				                	<div className='hrm-dialog-form hrm-rp-manage-date'>
				                	    {this.getForm()}
				                	</div>
                				</WeaRightMenu>
					}
				</div>)
	}
}