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('hrmWorkHour')
@observer
export default class SpecialForm extends React.Component {
	constructor(props) {
		super(props);
	}

	getForm() {
		const {
			hrmWorkHour
		} = this.props, {
			signFormInfo,
		} = hrmWorkHour, {
			form,
			conditions,
		} = signFormInfo, {
			isFormInit,
		} = form;

		let arr = [];
		isFormInit && conditions.map(c => {
			c.items.map((field, index) => {
				arr.push(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@dj8sgd@${index}`}
                            label={`${field.label}`}
                            labelCol={{span: 6, offset: 2}}
                            error={form.getError(field)}
                            tipPosition="bottom"
                            wrapperCol={{span: 14}}
                        >
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@813io5@${index}`} fieldConfig={field} form={form} formParams={form.getFormParams()} />
                                {index == 2 && <p>{`${i18n.label.format()}08:00-12:00  ${i18n.label.defalutSignTime()}`} </p>}
                                {index == 3 && <p>{`${i18n.label.format()}10.*.*.*;10.16.0.12;10.16.0.13-10.16.0.18`}</p>}
                        </WeaFormItem>)
			})
		})
		return <div className='wea-form-item-group'>{arr}</div>
	}

	getDropMenuDatas = () => {
		const {
			hrmWorkHour
		} = this.props, {
			signFormInfo
		} = hrmWorkHour, {
			loading
		} = signFormInfo;

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

		return menu
	}

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

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

	render() {
		const {
			hrmWorkHour
		} = this.props, {
			signFormInfo,
			date,
		} = hrmWorkHour, {
			loading,
		} = signFormInfo;

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

	}
}