import React, {
	Component
} from 'react';
import {
	WeaFormItem,
	WeaNewScroll,
	WeaSearchGroup,
} from 'ecCom';
import {
	WeaSwitch
} from 'comsMobx';

export default class AdvanceSearchFormInfo extends Component {
	renderGroupForm = () => {
		const {
			form,
			formFields,
			itemRender
		} = this.props;
		let formParams = form.getFormParams();
		let arr = [];
		formFields.map((c, i) => {
			let _arr = [];
			c.items.map((field, index) => {
				const customerRender = itemRender != null ? itemRender[field.domkey[0]] : null;
				const itemProps = {
					ratio1to2: true,
					label: field.label,
					labelCol: {
						span: `${window.HrmEngineLabelCol}`
					},
					error: form.getError(field),
					tipPosition: 'bottom',
					wrapperCol: {
						span: `${window.HrmEngineWrapperCol}`
					}
				}
				let coms;
				if (customerRender == null) {
					coms = <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@ywkcme@${index}`} fieldConfig={field} form={form}/>;
				} else {
					coms = customerRender(field, form, formParams);
				}
				coms != null && _arr.push({
					com: (
						<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@6i8xlx@${index}`} {...itemProps}>
                            {coms}
                        </WeaFormItem>
					),
					col: field.colSpan || 2
				})
			})
			arr.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@3imxgy@${i}`} showGroup={c.defaultshow} items={_arr} fontSize={13}/>);
		})
		return arr;
	}

	render() {
		return (
			<WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@73jbxg`} height={'100%'}>
			{this.renderGroupForm()}
			</WeaNewScroll>
		)
	}
}