import {
    WeaFormItem,
} from 'ecCom'

import {
    Spin,
} from 'antd'

import {
    WeaSwitch
} from 'comsMobx'

export default class Editor extends React.Component {
    constructor(props) {
        super(props);
    }

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

        let arr = [];
        isFormInit && condition.map(c => {
            c.items.map((field, index) => {
                arr.push(<WeaFormItem
                            label={`${field.label}`}
                            labelCol={{span: `${field.labelcol}`}}
                            error={form.getError(field)}
                            tipPosition="bottom"
                            wrapperCol={{span: `${field.fieldcol}`}}
                            underline={!authorized}
                        >
                                {<WeaSwitch fieldConfig={field} form={form} formParams={form.getFormParams()} />}
                        </WeaFormItem>)
            })
        })
        return <div className="wea-form-item-group">{arr}</div>
    }

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

        return (
            <Spin spinning={loading}>
                <div className='hrm-dialog-form'>
                    {this.getForm()}
                </div>
            </Spin>
        )
    }
}