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('./member').default;
                    this.setState({
                        component: <Member />,
                    });
                });
                break;
            case 'permission':
                require.ensure([], () => {
                    const Permission = require('./permission').default;
                    this.setState({
                        component: <Permission />,
                    });
                });
                break;
            case 'role':
                require.ensure([], () => {
                    const Role = require('./role').default;
                    this.setState({
                        component: <Role />,
                    });
                });
                break;
            case 'site':
                require.ensure([], () => {
                    const Site = require('./site').default;
                    this.setState({
                        component: <Site />,
                    });
                });
                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;
