import React from "react";
import {inject, observer} from "mobx-react";
import {WeaSwitch} from "comsMobx";
import {toJS} from "mobx";
import {
    WeaSearchGroup,
    WeaFormItem,
} from "ecCom";

const store = ["dataShowStore"];

@inject(...store)
@observer
export default class SqlTextForm extends React.Component {

    constructor(props) {
        super(props);
    }

    getItem = () => {
        const {dataShowStore} = this.props;
        const {sqlTextForm, status} = dataShowStore;
        const {} = toJS(status);
        const {form, condition} = sqlTextForm;
        const {isFormInit} = form;

        let arr = [];
        isFormInit && condition && condition.map((c, index) => {
            let items = [];
            c.items.map((field) => {
                items.push({
                    com: (<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@odwfbw@integrationDatashowsqlTestForm${field.domkey[0]}`}
                        label={`${field.label}`}
                        labelCol={{span: 5, offset: 2}}
                        wrapperCol={{span: 15}}
                        error={form.getError(field)}
                        tipPosition="bottom"
                        style={{padding: 10,}}
                    >
                        <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@r1svz7@integrationDatashowsqlTestForm${field.domkey[0]}`} fieldConfig={field} form={form} formParams={form.getFormParams()}/>

                    </WeaFormItem>),
                    colSpan: 1
                })
            });
            arr.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@wsysae@integrationDatashowsqlTestForm${index}`} center col={1} needTigger={true} title={c.title} showGroup={c.defaultshow}
                                     items={items}/>);
        });
        return <div style={{paddingTop: 15}}>{arr}</div>
    };

    render() {
        return (<div className='wea-integration-single'>
                    {this.getItem()}
                </div>)
    }
}