import '../../style/authSearch.less';
import React, {
	Component
} from 'react';
import {
	WeaTop,
	WeaAlertPage,
	WeaRightMenu
} from 'ecCom';
import {
	inject,
	observer
} from 'mobx-react';
import {Spin} from 'antd';
import Dashboard from './Dashboard';
import Content from './Content';
import {
	i18n
}from '../../public/i18n';
import {
	indexOf,
	has
} from 'lodash';

@inject("hrmAuthSearch")

@observer
export default class AuthSearch extends Component {
	constructor(props) {
		super(props);
	}

	componentDidMount() {
		this.init();
	}

	componentWillReceiveProps(nextProps) {
		if (this.props.location.key !== nextProps.location.key) {
			this.init();
		}
	}

	init = () => {
		const {
			hrmAuthSearch: store,
		} = this.props;
		const {
			checkAuthorized,
			initData
		} = store;
		checkAuthorized('permissionsearch', null, initData);
	}

	render() {
		const {
			hrmAuthSearch: store
		} = this.props;
		const {
			containerInitFinished,
			getMenu,
			spinning
		} = store;
		let menus = getMenu();
		const topProps = {
			title: i18n.module.authSearch(),
			icon: <i className='icon-coms-hrm'/>,
			iconBgcolor: '#217346',
			showDropIcon: true,
			dropMenuDatas: menus
		}

		return (
			<div className="hrm_module_container authSearch">
				{
					containerInitFinished.init && containerInitFinished.authorized && 
					<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@5gxt8r`} spinning={spinning}>
  	              	<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@f1lqm5`} {...topProps}>
  	              		<WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@ll0cjk`} datas={menus}>
	  	              		<Dashboard ecId={`${this && this.props && this.props.ecId || ''}_Dashboard@betmmz`} store={store}/>
	  	              		<Content ecId={`${this && this.props && this.props.ecId || ''}_Content@tmqdw7`} store={store}/>
  	              		</WeaRightMenu>
	              	</WeaTop>
					</Spin>
				}
				{
					containerInitFinished.init && !containerInitFinished.authorized && 
	              	<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@4lq76c`}>
	                  	<div style={{ color: '#000' }}>{i18n.message.authFailed()}</div>
	              	</WeaAlertPage>
				}
			</div>
		)
	}
}