import React, { Component } from 'react';
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("normal");
        };
    }
    getKey(key) {
        switch (key) {
            case 'normal':
                require.ensure([], () => {
                    const Normal = require('./normal').default;
                    this.setState({
                        component: Normal
                    });
                });
                break;
            case 'collection':
                require.ensure([], () => {
                    const Collection = require('./collection').default;
                    this.setState({
                        component: Collection
                    });
                });
                break;
            case 'orderList':
                require.ensure([], () => {
                    const OrderList = require('./orderList').default;
                    this.setState({
                        component: OrderList
                    });
                });
                break;
        };
        window.location.hash = key;
    }
    render() {
        return (
            <div className="acc-content">
                <LeftTab handlekey={this.getKey.bind(this)} />
                <div className="content-right">
                    <this.state.component />
                </div>
            </div>
        )
    }
}

export default Content;
