import {
    inject,
    observer
} from 'mobx-react'
import {
    WeaDialog,
    WeaRightMenu
} from 'ecCom'

//根据情况import组件
import SubTab from './SubTab';
import FormInfoWithTable from './FormInfoWithTable';
import FormInfo from './FormInfo';
import SubTable from './SubTable';
import TableEdit from './TableEdit';
import Print from './Print';

@inject('hrmRecruitLibrary') //todo
@observer
export default class MainDialog extends React.Component {
    constructor(props) {
        super(props);
    }

    getChildren = () => {
        //根据this.mainTable.index值来返回对应的组件
        const {
            hrmRecruitLibrary
        } = this.props, {
            mainTable,
            subTab,
            formInfo,
        } = hrmRecruitLibrary, {
            index
        } = mainTable, {
            curKey
        } = subTab, {
            errorMsg
        } = formInfo;

        if (['new', 'sendMail', '2', '6', '7', '9'].includes(index)) {
            return errorMsg ? <p style={{textAlign: 'center',paddingTop: 270, fontSize: 18,color: '#FF0000'}}>{errorMsg}</p> : <FormInfo ecId={`${this && this.props && this.props.ecId || ''}_FormInfo@ip7kbl`} />
        }
        if (index == '1') {
            return (<div>
                      <SubTab ecId={`${this && this.props && this.props.ecId || ''}_SubTab@nna4za`} />
                      {curKey == '0' ? <FormInfo ecId={`${this && this.props && this.props.ecId || ''}_FormInfo@7si9g3`} /> : <FormInfoWithTable ecId={`${this && this.props && this.props.ecId || ''}_FormInfoWithTable@3skmxq`} />}
                    </div>)
        }
        if (['3', '4', '5'].includes(index)) {
            return (<div>
                        <SubTab ecId={`${this && this.props && this.props.ecId || ''}_SubTab@32ztw0`} />
                        {curKey == '0' ? <FormInfo ecId={`${this && this.props && this.props.ecId || ''}_FormInfo@q9vecl`} /> : <SubTable ecId={`${this && this.props && this.props.ecId || ''}_SubTable@qyl5cj`} />}
                    </div>)
        }
        if (index == '8') {
            return (<div>
                        <SubTab ecId={`${this && this.props && this.props.ecId || ''}_SubTab@1wdtkd`} />
                        <SubTable ecId={`${this && this.props && this.props.ecId || ''}_SubTable@usf7hs`} />
                    </div>)
        }
    }

    render() {
        const {
            hrmRecruitLibrary
        } = this.props, {
            mainDialog,
            closeDialog,
            buttons,
            style,
            dropMenuDatas,
        } = hrmRecruitLibrary, {
            title,
            visible,
        } = mainDialog;

        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@735gqp`}
                title={title}
                icon="icon-coms-hrm"
                iconBgcolor="#217346"
                visible={visible}
                hasScroll={true}
                onCancel={() => closeDialog()}
                buttons={buttons}
                style={style}
            >
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@jj5l3k`} datas={dropMenuDatas}>
                    {visible && this.getChildren()}
                </WeaRightMenu>
            </WeaDialog>
        )

    }
}