import React, { Component } from 'react';
import '../content.less';
import LeftTab from '../leftTab';
import {getMenu} from '../publicMenu.jsx'

class Content extends Component {
    constructor() {
        super();
        this.state = {
            loading: false,
            component: <div></div>,
        };
    }
    componentWillMount() {
        var ids=window.location.href.indexOf('rid=');
        var idk=window.location.href.substr(ids+4);
        var rid=idk.split('#');
        let menu=getMenu(rid);
        let curry;
        if(menu[0].subMenus.length>0){
        	curry=menu[0].subMenus[0].url.split('#');
        }else{
        	curry=menu[0].url.split('#');
        };
        if (window.location.hash) {
            this.getKey(window.location.hash.substr(1));
        } else {
         this.getKey(curry[1]);
        };
    }
    getKey(key) {
        switch (key) {          	
            case 'myOrganization':
                require.ensure([], () => {
                    const MyClient = require('./customerData/myClient').default;
                    this.setState({
                        component: <MyClient />                      
                    });
                });
                break;           
            case 'organizationQuery':
                require.ensure([], () => {
	                const CompanyCustomer = require('./customerData/companyCustomer').default;
	                this.setState({
	                    component:<CompanyCustomer />,	                    	                  
	                });
          	    });
          	    break;
          	case 'myPersonal':
                require.ensure([], () => {
                    const IndividualCustomer = require('./individualCustomer/individualCustomer').default;
                    this.setState({
                        component: <IndividualCustomer />                      
                      
                    });
                });
                break;          
            case 'personalQuery':
                require.ensure([], () => {
	                const QueryCustomer = require('./individualCustomer/queryCustomer').default;
	                this.setState({
	                    component:<QueryCustomer />,	                    	                  
	                });
          	    });
          	    break;
      	    case 'myBusiness':
            require.ensure([], () => {
                const MyBusiness = require('./customerService/myBusiness').default;
                this.setState({
                    component:<MyBusiness />,	                                      
                });
      	    });
      	    break;
      	    case 'businessQuery':
            require.ensure([], () => {
                const ServiceQuery = require('./customerService/serviceQuery').default;
                this.setState({
                    component:<ServiceQuery />,	                                      
                });
      	    });
      	    break;
      	    case 'visitStatistics':
            require.ensure([], () => {
                const VisitStatistics = require('./statistics/visitStatistics').default;
                this.setState({
                    component:<VisitStatistics />,	                                      
                });
      	    });
      	    break;
      	    case 'statusStatistics':
            require.ensure([], () => {
                const StatusStatistics = require('./statistics/statusStatistics').default;
                this.setState({
                    component:<StatusStatistics />,	                                      
                });
      	    });
      	    break;
      	    case 'followStatistics':
            require.ensure([], () => {
                const FollowStatistics = require('./statistics/followStatistics').default;
                this.setState({
                    component:<FollowStatistics />,	                                      
                });
      	    });
      	    break;
      	    default:
            require.ensure([], () => {
                const Module = require('../module').default;
                this.setState({
                    component:<Module />	    
                	});
                });  
        };
        window.location.hash = key;
    }
    render() {
        return (
            <div className="manage-content">
                <LeftTab handlekey={this.getKey.bind(this)} />
                <div className="content-right">
                   {this.state.component}
                </div>
            </div>
        )
    }
}

export default Content;
