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


class Content extends Component {
    constructor() {
        super();
        this.state = {
            loading: false,
            component: <div />,
        };
    }
    componentWillMount() {
        if (window.location.hash) {
            this.getKey(window.location.hash.substr(1));
        } else {
            this.getKey('member');
        };
    }
    getKey(key) {
        switch (key) {
            case 'member':
                require.ensure([], () => {
                    const Member = require('./userManagement/member').default;
                    this.setState({
                        component: <Member />                      
                    });
                });
                break;           
           
            case 'permission':
                require.ensure([], () => {
	                const Permission = require('./userManagement/permission').default;
	                this.setState({
	                    component:<Permission />,	                    	                  
	                });
          	    });
          	    break;
          	case 'role':
                require.ensure([], () => {
                    const Role = require('./userManagement/role').default;
                    this.setState({
                        component: <Role />                      
                      
                    });
                });
                break;  
            case 'site':
	            require.ensure([], () => {
	                const Site = require('./userManagement/site').default;
	                this.setState({
	                    component: <Site />,
	                });
	            });
            break;
      	    case 'organization':
            require.ensure([], () => {
                const Organization = require('./organization/organization').default;
                this.setState({
                    component:<Organization />,	                                      
                });
      	    });
      	    break;
      	    case 'businessCategory':
            require.ensure([], () => {
                const BusinessCategory = require('./business/businessCategory').default;
                this.setState({
                    component:<BusinessCategory />	    
                	});
                });
                break; 
            case 'businessProject':
            require.ensure([], () => {
                const BusinessProject = require('./business/businessProject').default;
                this.setState({
                    component:<BusinessProject />	    
                	});
                });
            break; 
            case 'user':
                require.ensure([], () => {
                    const User = require('./userManagementS/user').default;
                    this.setState({
                        component: <User />                      
                    });
                });
                break;           
           
            case 'roles':
                require.ensure([], () => {
	                const Roles = require('./userManagementS/roles').default;
	                this.setState({
	                    component:<Roles />,	                    	                  
	                });
          	    });
          	    break;
          	case 'jurisdiction':
                require.ensure([], () => {
                    const Jurisdiction = require('./userManagementS/jurisdiction').default;
                    this.setState({
                        component: <Jurisdiction />                      
                    });
                });
                break;  
        };
        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;
