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

import SubTab from './SubTab';
import LoginSetting from './LoginSetting';
import SubTable from './SubTable';
import LoginTestForm from './LoginTestForm';
import AlgorithmFormSetting from './AlgorithmFormSetting';
import AlgorithmTestForm from './AlgorithmTestForm';
import TypeFormSetting from './TypeFormSetting';
import HRMNetworkIPList from '../../public/HRMNetworkIPList';

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

    getChildren = () => {
        const {
            intelogin
        } = this.props, {
            mainDialog,
            mainTab,
            subTab,
        } = intelogin, {
            type
        } = mainDialog, {
            key
        } = subTab;

        const mkey = mainTab.key;

        if (type == 'BTN_NEW') {
            return <LoginSetting ecId={`${this && this.props && this.props.ecId || ''}_LoginSetting@1shre9`} type={this.props.type} />
        }
        if (type == 'encrypt_new') {
            return <AlgorithmFormSetting ecId={`${this && this.props && this.props.ecId || ''}_AlgorithmFormSetting@eajufi`} />
        }
        if (type == 'BTN_TYPE_NEW') {
            return <TypeFormSetting ecId={`${this && this.props && this.props.ecId || ''}_TypeFormSetting@yv75vt`} />
        }
        if (mkey == '0') {
            if (type == '0') {
                return (
                    <div>
                    <SubTab ecId={`${this && this.props && this.props.ecId || ''}_SubTab@vcxd53`} />
                    {key == '0' ? <LoginSetting ecId={`${this && this.props && this.props.ecId || ''}_LoginSetting@tidu6o`} /> : <SubTable ecId={`${this && this.props && this.props.ecId || ''}_SubTable@yd1kew`} />}
                </div>
                )
            }
            if (type == '2') {
                return <LoginTestForm ecId={`${this && this.props && this.props.ecId || ''}_LoginTestForm@cybx3e`} />
            }
        } else if(mkey == '1') {
            if (type == '0') {
                return <AlgorithmFormSetting ecId={`${this && this.props && this.props.ecId || ''}_AlgorithmFormSetting@81q1fp`} />
            }
            if (type == '2') {
                return <AlgorithmTestForm ecId={`${this && this.props && this.props.ecId || ''}_AlgorithmTestForm@br3yaf`} />
            }
        } else if(mkey == '2') {
            if (type == '0') {
                return <TypeFormSetting ecId={`${this && this.props && this.props.ecId || ''}_TypeFormSetting@eork4i`} />
            }
        }

    }

    render() {
        const {
            intelogin
        } = this.props, {
            mainDialog,
            closeDialog,
            mstyle,
            getDialogFooter,
            HRMNetworkListVisible,
            setHRMNetworkListVisible
        } = intelogin, {
            title,
            visible,
        } = mainDialog, {
            buttons=[],
            dropMenuDatas=[],
        } = getDialogFooter({type: this.props.type});

        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@jlyd7j`}
                title={title}
                icon='icon-coms-integration'
                iconBgcolor="#1a57a0"
                visible={visible}
                hasScroll={true}
                onCancel={closeDialog}
                buttons={buttons}
                style={mstyle}
                moreBtn={{datas:dropMenuDatas}}
            >
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@18i2br`} datas={dropMenuDatas}>
                    {visible && this.getChildren()}
                    <HRMNetworkIPList ecId={`${this && this.props && this.props.ecId || ''}_HRMNetworkIPList@reo3eg`} 
                      visible={HRMNetworkListVisible}
                      onCancel={() => setHRMNetworkListVisible(false)}
                    />
                </WeaRightMenu>
            </WeaDialog>
        )

    }
}
