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

@inject("hrmAuthAdjust")

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

	componentDidMount() {
		this.init();
	}

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

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

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

		const {
			location
		} = this.props;

		let comp;
		if(hideTop){
			comp = <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@p6p8rl`} datas={menus} >
					<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@kzlos0`} spinning={showSpin}>
						<Dashboard ecId={`${this && this.props && this.props.ecId || ''}_Dashboard@ae4h5l`} store={store}/>
						<Content ecId={`${this && this.props && this.props.ecId || ''}_Content@tojv57`} store={store}/>
					</Spin>
				</WeaRightMenu>
		}else{
			comp = <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@yphsaz`} {...topProps}>
				<WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@esc4lb`} datas={menus} >
					<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@5kjohl`} spinning={showSpin}>
						<Dashboard ecId={`${this && this.props && this.props.ecId || ''}_Dashboard@2l1vw1`} store={store}/>
						<Content ecId={`${this && this.props && this.props.ecId || ''}_Content@ud47te`} store={store}/>
					</Spin>
				</WeaRightMenu>
			</WeaTop>
		}
		return (
			<div className="hrm_module_container authAdjust">
				{
					containerInitFinished.init && containerInitFinished.authorized && 
					comp
				}
				{
					containerInitFinished.init && !containerInitFinished.authorized && 
	              	<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@khobqw`}>
	                  	<div style={{ color: '#000' }}>{i18n.message.authFailed()}</div>
	              	</WeaAlertPage>
				}
			</div>
		)
	}
}