import React, {Component} from 'react';
import {observer} from 'mobx-react';
import {WeaDialog,WeaTableEdit,WeaNewScroll} from 'ecCom';
import {Button} from 'antd';
import {i18n} from '../../public/i18n';
import * as mobx from 'mobx';
const toJS = mobx.toJS;

@observer
export default class Edit extends Component{
    render(){
        const {
			store
        } = this.props;
        const {
            dialogParams,
            editTable,
            onEditTableChange,
            savePerson,
            setEditTable,
            canAdd
        } = store;
        const generateDialogParams = () =>{
            const props = {...dialogParams};
            let buttons = canAdd ? [<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@8upqjs`} type='primary' op='save' onClick={() => savePerson()}>{i18n.label.save()}</Button>] : [];
            Object.assign(props, {
                buttons,
                moreBtn: {datas: store.convertToMenus(buttons)},
                // key: new Date().getTime()
            })
            return props;
        }

        const editProps = canAdd ? {} : {
            showAdd: false,
            showCopy: false,
            showDelete: false,
            showMove: false
        }
        
        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@x4r52w`} {...generateDialogParams()}>
                <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@7vo5zj`} height={'100%'}>
                    <WeaTableEdit ecId={`${this && this.props && this.props.ecId || ''}_WeaTableEdit@6nuqec`}
                        viewAttr={2}
                        columns={toJS(editTable.columns)}
                        datas={toJS(editTable.datas)}
                        onChange={datas => {
                            onEditTableChange(datas);    
                          }}
                        ref={(editTable) => setEditTable(editTable, 'fieldDef')}
                        {...editProps}
                    />
                </WeaNewScroll>
            </WeaDialog>
        )
    }
}