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


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(window.showCustomer ? 'customerList' : 'userList');
        };
    }
    getKey(key) {
        switch (key) {
            case 'userList':
                require.ensure([], () => {
                    const UserList = require('./userList').default;
                    this.setState({
                        component: <UserList />,
                    });
                });
                break;
            case 'orgList':
                require.ensure([], () => {
                    const OrgList = require('./orgList').default;
                    this.setState({
                        component: <OrgList />,
                    });
                });
                break;
            case 'customerList':
                require.ensure([], () => {
                    const CustomerList = require('./customerList').default;
                    this.setState({
                        component: <CustomerList />,
                    });
                });
                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;
