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></div>,
        };
    }
    componentWillMount () {
        if (window.location.hash) {
            this.getKey(window.location.hash.substr(1));
        } else {
            this.getKey("membership");
        };
    }
    getKey (key) {
        switch (key) {
            case 'membership':
                require.ensure([], () => {
                    const Membership = require('./memberOrderList').default;
                    this.setState({
                        component: <Membership />
                    });
                });
                break;
            case 'consult':
                require.ensure([], () => {
                    const Consult = require('./consultOrderList').default;
                    this.setState({
                        component: <Consult />
                    });
                });
                break;
            case 'userAchievementOrder':
                require.ensure([], () => {
                    const AchievementOrder = require('../achievement/achievementOrder').default;
                    this.setState({
                        component: <AchievementOrder
                            data-listApiUrl='/api/admin/portal/order/userAchievementOrderList'
                            data-detailApiUrl='/api/admin/achievement/userDetail' />
                    });
                });
                break;
            case 'orgAchievementOrder':
                require.ensure([], () => {
                    const AchievementOrder = require('../achievement/achievementOrder').default;
                    this.setState({
                        component: <AchievementOrder
                            data-listApiUrl='/api/admin/portal/order/orgAchievementOrderList'
                            data-detailApiUrl='/api/admin/achievement/orgDetail' />
                    });
                });
                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;
