import {
	inject,
	observer,
} from 'mobx-react'
import {
	WeaFormItem,
} from 'ecCom'
import {
	WeaSwitch
} from 'comsMobx'

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

	getForm() {
		const {
			hrmPersonalSalaryAdjustment
		} = this.props, {
			editor,
		} = hrmPersonalSalaryAdjustment, {
			form,
			condition,
		} = editor, {
			isFormInit,
		} = form;

		const salaryInputItem =condition && condition.length && condition[0].items.find(item=>item.domkey[0] === 'salary');

		let arr = [];
		isFormInit && condition.map(c => {
			c.items.map((field, index) => {
				const {domkey} = field;
				if (domkey[0] === 'salary') {
					return;
				}
				arr.push(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@jr337l@${index}`}
                            label={`${field.label}`}
                            labelCol={index == 0 ? {span: 0} : {span: 6}}
                            colon={index == 0 ? false : true}
                            error={form.getError(field)}
                            tipPosition="bottom"
                            wrapperCol={index == 0 ? {span: 20} : {span: 18}}
                        >
                                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@g4b3xb@${index}`} fieldConfig={field} form={form} formParams={form.getFormParams()} />
                       			{
                       				domkey[0] === 'changetype' && (
                       					<div className='salary'>
                       						<WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@256elo@${index}`} fieldConfig={salaryInputItem} form={form} formParams={form.getFormParams()} />
                       					</div>
                       				)
                       			}
                        </WeaFormItem>)
			})
		})
		return <div className='wea-form-item-group hrm-salary-adjust-select'>{arr}</div>
	}

	render() {
		const {
			hrmPersonalSalaryAdjustment
		} = this.props, {
			editor,
		} = hrmPersonalSalaryAdjustment, {
			loading,
			date,
		} = editor;

		return (
			<div style={{width: '46%',marginLeft: '26%',marginTop:90}}>
                {this.getForm()}
            </div>
		)

	}
}