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

import '../../style/searchGroupRelated.css'

import Header from './Header';
import Content from './Content';
import Add from './Add';

@inject('hrmConExWarning')
@observer
export default class ConExWarning 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.contractExpireWarning();
		}
	}

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

	componentDidMount() {
		this.init();
	}

	init() {
		this.props.hrmConExWarning.getAuth();
	}

	render() {
		const {
			hrmConExWarning
		} = this.props, {
			main,
		} = hrmConExWarning, {
			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@zwckst`} spinning={loading} size='large'></Spin>
								</div>
						     :	<div className="hrm-wea-alert-page">
		                			<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@gd2hk7`}>
						                <div style={{ color: '#000' }}>
						                    {i18n.message.authFailed()}
						                </div>
		                      		</WeaAlertPage>
	                        	</div>
	                }	
                </div>
			)
		} else {
			return (
				<div style={{height: '100%'}}>
					<Header ecId={`${this && this.props && this.props.ecId || ''}_Header@9adl4j`}>
						<Content ecId={`${this && this.props && this.props.ecId || ''}_Content@2glz5l`} />
					</Header>
					<Add ecId={`${this && this.props && this.props.ecId || ''}_Add@z9kqph`} />
				</div>
			)
		}
	}

}