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

import '../../style/trainActivity.css'

import Header from './Header';
import ActivityTab from './ActivityTab';
import MainDialog from './MainDialog';
import SubDialog from './SubDialog';

@inject('hrmTrainActivity')
@observer
export default class TrainActivity 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.trainActivity();
		}
	}

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

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

	componentDidMount() {
		this.init();
	}

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

		getAuth();
	}

	render() {
		const {
			hrmTrainActivity
		} = this.props, {
			main,
		} = hrmTrainActivity, {
			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@luue66`} spinning={loading} size='large'></Spin>
								</div>
						     :	<div className="hrm-wea-alert-page">
		                			<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@0ijeeg`}>
						                <div style={{ color: '#000' }}>
						                    {i18n.message.authFailed()}
						                </div>
		                      		</WeaAlertPage>
	                        	</div>
	                }	
                </div>
			)
		} else {
			return (
				<div className='hrm-activity-right-menu'>
					<Header ecId={`${this && this.props && this.props.ecId || ''}_Header@5hl25y`}>
						<ActivityTab ecId={`${this && this.props && this.props.ecId || ''}_ActivityTab@ltewet`} />
					</Header>
					<MainDialog ecId={`${this && this.props && this.props.ecId || ''}_MainDialog@cwtw8j`} />
					<SubDialog ecId={`${this && this.props && this.props.ecId || ''}_SubDialog@lg8ko6`} />
				</div>
			)
		}
	}


}