import React, {Component} from 'react';
import {observer} from 'mobx-react';
import {WeaFormItem, WeaSearchGroup} from 'ecCom';
import {WeaSwitch} from 'comsMobx';

@observer
export default class Form extends Component{
    getForm = () => {
        const {store: {edit, formProps}} = this.props;
        const {col, form, formFields = []} = formProps;

        const groupArr = [];
        formFields.map((group, i) => {
            const items = [];
            group.items.map((field, j) => {
                const itemProps = {
                    underline: !edit,
                    label: field.label,
                    labelCol: {span: window.HrmLabelCol},
                    wrapperCol: {span: window.HrmWrapperCol}
                }
                items.push({
					com: (
						<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@2xkutm@${j}`} {...itemProps}>
							<WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@mf5372@${j}`} fieldConfig={field} form={form} />
						</WeaFormItem>
					),
					col
				})
            });

            const groupProps = {
                title: group.title,
                showGroup: group.defaultshow,
                items,
                col,
                fontSize: 14
            }

            groupArr.push(
                (
                    <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@pr042o`} {...groupProps} />
                )
            );
        });

        return groupArr;
    }

    render(){
        return (
            <div className='form_container'>
                {this.getForm()}
            </div>
        )
    }
}