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

//根据情况import组件
import SubTab from './SubTab';
import FormInfo from './FormInfo';
import TableEdit from './TableEdit';
import RecruitLibrary from '../recruitLibrary/index';

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

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

        if (index == 'new') {
            return <FormInfo ecId={`${this && this.props && this.props.ecId || ''}_FormInfo@mxoo7s`} />
        }
        if (index == '1') {
            return (<div>
                      <SubTab ecId={`${this && this.props && this.props.ecId || ''}_SubTab@8air21`} />
                      {curKey == '0' ? <FormInfo ecId={`${this && this.props && this.props.ecId || ''}_FormInfo@ai39mp`} /> :(curKey == '1') ? <TableEdit ecId={`${this && this.props && this.props.ecId || ''}_TableEdit@rkip4u`} /> : <RecruitLibrary ecId={`${this && this.props && this.props.ecId || ''}_RecruitLibrary@rqpa39`} inviteInfoId={id} onRef={this.onRef} setSelectedRowKeys={keys => setSelectedRowKeys(keys)}/>}
                    </div>)
        }
    }

    onRef = (ref) => {
        this.props.hrmRecruitInfo.setChildRef(ref);
    }

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

        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@raqb1d`}
                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@06cb9w`} datas={dropMenuDatas}>
                    {visible && this.getChildren()}
                </WeaRightMenu>
            </WeaDialog>
        )

    }
}