import React from 'react';
import { Menu, Icon } from 'antd';
import '../leftTab.less';
const SubMenu = Menu.SubMenu;
const MenuItemGroup = Menu.ItemGroup;
import { Link } from 'react-router';
import ajax from 'jquery/src/ajax/xhr.js';
import $ from 'jquery/src/ajax';
import { menu } from '@/account/menu';
import logo from 'img/acc-logo.png';

const LeftTab = React.createClass({
	getInitialState() {
		return {
			openKeys: [ 'sub1' ],
			current: 'account'
		};
	},
	loadData() {
		$.ajax({
			method: 'post',
			dataType: 'json',
			url: globalConfig.context + '/api/admin/customer/left',
			data: {}
		}).done(
			function(data) {
				if (!data.data.error.length) {
					this.setState({
						state: data.data.aa
					});
				} else {
					message.warning(data.error[0].message);
				}
			}.bind(this)
		);
	},
	menuClick(e) {
		this.setState({
			current: e.key
        });
        window.location.hash=e.key;
	},
	componentWillMount() {
		this.loadData();
		if (window.location.hash) {
            let current = window.location.hash.substr(2);
            this.setState({
                current
            })
        }
	},
	render() {
        console.log(this.state.current)
		return (
			<div>
				<div className="acc-index">
						<img src={logo} alt="" />
                        <span>
					    	<a href={globalConfig.context + '/user/account/index.html'}>会员中心首页</a>
					    </span>
				</div>
				<Menu
					onClick={this.menuClick}
					defaultOpenKeys={this.state.openKeys}
					selectedKeys={[ this.state.current ]}
                    mode="inline"
                    theme='light'
					className="account-left"
				>
					{menu.map((subMenu) => {
						if (subMenu.children && subMenu.children.length) {
							return (
								<SubMenu
									key={subMenu.url}
									title={
										<span>
											<Icon type={subMenu.icon} />
											<span>{subMenu.name}</span>
										</span>
									}
								>
									{subMenu.children.map((menu) => (
										<Menu.Item key={menu.url}>
											{menu.name}
										</Menu.Item>
									))}
								</SubMenu>
							);
						}
						return (
							<Menu.Item key={subMenu.url}>
								<Link to={`/${subMenu.url}`}>
									<Icon type={subMenu.icon} />
									<span className="nav-text">{subMenu.name}</span>
								</Link>
							</Menu.Item>
						);
					})}
				</Menu>
			</div>
		);
	}
});

export default LeftTab;

// <Menu.Item key="base">
//     基本信息
// </Menu.Item>
// <Menu.Item key="person">
//     个人资料
// </Menu.Item>
// <Menu.Item key="edu">
//     教育信息
// </Menu.Item>
// <Menu.Item key="pfs">
//     职业信息
// </Menu.Item>
// <Menu.Item key="ablt">
//     能力标签
// </Menu.Item>
