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

import Header from './Header';
import Tab from './Tab';
import MainDialog from './MainDialog';

@inject('hrmEmployDemand')
@observer
export default class EmployDemand 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.employDemand();
		}
	}

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

	componentDidMount() {
		this.init();
	}

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

		getAuth();
	}

	render() {
		const {
			hrmEmployDemand
		} = this.props, {
			main,
		} = hrmEmployDemand, {
			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@q92ie1`} spinning={loading} size='large'></Spin>
								</div>
						     :	<div className="hrm-wea-alert-page">
		                			<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@peimpn`}>
						                <div style={{ color: '#000' }}>
						                    {i18n.message.authFailed()}
						                </div>
		                      		</WeaAlertPage>
	                        	</div>
	                }	
                </div>
			)
		} else {
			return (
				<div>
					<Header ecId={`${this && this.props && this.props.ecId || ''}_Header@a288jc`}>
						<Tab ecId={`${this && this.props && this.props.ecId || ''}_Tab@j11sg4`} />
					</Header>
					<MainDialog ecId={`${this && this.props && this.props.ecId || ''}_MainDialog@umfkoc`} />
				</div>
			)
		}
	}


}