import '../../style/matrixAdjust.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 Result from './Result';
import {
	i18n
} from '../../public/i18n';

@inject("hrmMatrixAdjust")

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

	componentDidMount() {
		this.init();
	}

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

	init = () => {
		const {
			hrmMatrixAdjust: store,
		} = this.props;
		const {
			checkAuthorized,
			initData
		} = store;
		checkAuthorized('matrix/pages/matrixMassMaint', null, () => initData(this.props.location.query));
	}

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

		return (
			<div className="hrm_module_container matrixAdjust">
				{
					containerInitFinished.init && containerInitFinished.authorized && 
  	              	<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@j2in5y`} {...topProps}>
  	              		<WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@mb69x8`} datas={menus} >
							{
								showResult 
								? 
								<Result ecId={`${this && this.props && this.props.ecId || ''}_Result@3opg6m`} store={store} />
								:
								<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@z7yday`} spinning={showSpin}>
									<Dashboard ecId={`${this && this.props && this.props.ecId || ''}_Dashboard@orqjxv`} store={store}/>
									<Content ecId={`${this && this.props && this.props.ecId || ''}_Content@zwst2b`} store={store}/>
								</Spin>
							}
  	              		</WeaRightMenu>
	              	</WeaTop>
				}
				{
					containerInitFinished.init && !containerInitFinished.authorized && 
	              	<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@bpnorr`}>
	                  	<div style={{ color: '#000' }}>{i18n.message.authFailed()}</div>
	              	</WeaAlertPage>
				}
			</div>
		)
	}
}