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

import SubTab from './SubTab';
import FormInfo from './FormInfo';
import TableEdit from './TableEdit';
import RecruitInfo from '../recruitInfo/index';

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

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

        if (index == 'new' || index == '3') {
            return <FormInfo ecId={`${this && this.props && this.props.ecId || ''}_FormInfo@3ili7z`} />
        }
        if (index == '0') {
            return (<div>
                      <SubTab ecId={`${this && this.props && this.props.ecId || ''}_SubTab@nwswzz`} />
                      {curKey == '0' ? <FormInfo ecId={`${this && this.props && this.props.ecId || ''}_FormInfo@bs7x2i`} /> : (curKey == '2') ? <RecruitInfo ecId={`${this && this.props && this.props.ecId || ''}_RecruitInfo@h99gtj`} id={id} onRef={this.onRef} setSelectedRowKeys={keys => setSelectedRowKeys(keys)}/> : <TableEdit ecId={`${this && this.props && this.props.ecId || ''}_TableEdit@ehd2jx`} />}
                    </div>)
        }
    }

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

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

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

    }
}