import React, {Component} from 'react';
import {observer} from 'mobx-react';
import {WeaDialog} from 'ecCom';
import {Button} from 'antd';
import {i18n} from '../../public/i18n';
import Info from './Info';
import BaseInfo from './info/BaseInfo';

@observer
export default class Edit extends Component{
    constructor(props){
        super(props);
        this.state = {
            height: 0
        }
    }
    render(){
        const {height} = this.state;
        const {
			store
        } = this.props;
        const {
            dialogParams,
            save,
            canAdd,
        } = store;
        const generateDialogParams = () =>{
            const props = {...dialogParams};
            let buttons = canAdd ? [<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@k8bo3`} type='primary' op='save' onClick={() => save()}>{i18n.label.save()}</Button>] : [];
            if(dialogParams.opType === 'create' && canAdd){
                buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@esd8bp`} type='primary' op='entry' onClick={() => save(true)}>{i18n.label.saveAndSetting()}</Button>)
            }
            Object.assign(props, {
                buttons,
                moreBtn: {datas: store.convertToMenus(buttons)},
                // key: new Date().getTime()
            })
            return props;
        }
        
        const getContent = () => {
            if(dialogParams.opType == 'create'){
                return (
                    <BaseInfo ecId={`${this && this.props && this.props.ecId || ''}_BaseInfo@3ri22a`} store={store} />
                );
            }else{
                return (
                    <Info ecId={`${this && this.props && this.props.ecId || ''}_Info@j0kdfv`} store={store} height={height}/>
                );
            }
        }
        
        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@2l5h9w`} {...generateDialogParams()} onChangeHeight={(h) => this.setState({height: h})}>
                {getContent()}
            </WeaDialog>
        )
    }
}