import React from 'react'
import {
	inject,
	observer,
} from 'mobx-react'
import {
	WeaAlertPage,
} from 'ecCom'
import {
	Spin,
} from 'antd'
import {
	i18n
} from '../../public/i18n';
import '../../style/trainArrange.css'

import Header from './Header';
import Search from './Search';
import MainTableInfo from './MainTableInfo';
import MainDialog from './MainDialog';
import SubDialog from './SubDialog';

@inject('hrmTrainArrange')
@observer
export default class TrainArrange extends React.Component {
	constructor(props) {
		super(props);
	}

	componentWillMount() {
		let bool = window.location.href.indexOf('/spa/hrm/engine.html') > -1;
		if (bool) {
			document.title = i18n.module.trainArrange();
		}
	}

	componentWillReceiveProps(nextProps) {
		const {
			hrmTrainArrange
		} = this.props, {
			refreshPage
		} = hrmTrainArrange;

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

	componentDidMount() {
		this.init();
	}

	init() {
		const {
			hrmTrainArrange
		} = this.props, {
			getAuth
		} = hrmTrainArrange;

		getAuth();
	}

	render() {
		const {
			hrmTrainArrange
		} = this.props, {
			main,
		} = hrmTrainArrange, {
			authorized,
			loading
		} = main;

		if (!authorized) {
			return (
				<div style={{height: '100%'}}>
					{loading ?  <div className='hrm-loading-center'>
									<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@me88ez`} spinning={loading} size='large'></Spin>
								</div>
						     :	<div className="hrm-wea-alert-page">
		                			<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@f9vt7q`}>
						                <div style={{ color: '#000' }}>
						                    {i18n.message.authFailed()}
						                </div>
		                      		</WeaAlertPage>
	                        	</div>
	                }	
                </div>
			)
		} else {
			return (
				<div className='hrm-arrange-right-menu'>
					<Header ecId={`${this && this.props && this.props.ecId || ''}_Header@nfdk95`}>
						<Search ecId={`${this && this.props && this.props.ecId || ''}_Search@7ktrzy`} />
						<MainTableInfo ecId={`${this && this.props && this.props.ecId || ''}_MainTableInfo@bda20a`} />
					</Header>
					<MainDialog ecId={`${this && this.props && this.props.ecId || ''}_MainDialog@pnqt11`} />
					<SubDialog ecId={`${this && this.props && this.props.ecId || ''}_SubDialog@4gmwsu`} />
				</div>
			)
		}
	}


}