import React, { Component } from 'react'
import {observer} from 'mobx-react';
import {toJS} from 'mobx';
import {WeaDialog,WeaFormItem, WeaSearchGroup, WeaLocaleProvider} from 'ecCom';
import {WeaSwitch} from 'comsMobx';
const getLabel = WeaLocaleProvider.getLabel;


@observer
export default class AddToGroup extends Component {
    
    getContent (condition) {
        const {store} = this.props;
        const {addToGroupForm, chooseGroup} = store;

        const {isFormInit} = addToGroupForm;
        let group = [];
      isFormInit && toJS(condition).map((c, i) =>{
        let items = [];
        c.items.map((field, index) => {
          items.push({
            com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@5ummuk@${index}`}
                label={getLabel('515195','选择考勤组')}
                labelCol={{span: `${field.labelcol}`}}
                ratio1to2
                error={addToGroupForm.getError(field)}
                tipPosition="bottom"
                wrapperCol={{span: `${field.fieldcol}`}}>
                  <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@dy200w@${index}`} fieldConfig={{...field, title:getLabel('515195','选择考勤组')}} form={addToGroupForm} onChange = {(data) => chooseGroup (data)} title='选择考勤组' />
                </WeaFormItem>),
          })
        });
        group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@wfif9o@${i}`} style={{paddingTop:'15px'}} center = {true} showGroup={c.defaultshow} items={items}/>)
      });
      return group;
    }


    render() {
        const {store} = this.props;
        const {addToGroupCondition,addDialogParams,buttons} = store;
        return (
            <div>
                <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@kls7pc`} {...addDialogParams} buttons={buttons} >
                    {
                        this.getContent(addToGroupCondition)
                    }
                </WeaDialog>
            </div>
        )
    }
}
