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 Content from './Content';
import MainDialog from './MainDialog';

import '../../style/attendanceSetting.css'

@inject('hrmAttendanceSetting')
@observer
export default class AttendanceSetting 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.attendanceSetting();
		}
	}

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

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

	componentDidMount() {
		this.init();
	}

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

		getAuth();
	}

	render() {
		const {
			hrmAttendanceSetting
		} = this.props, {
			main,
		} = hrmAttendanceSetting, {
			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@t7g7iu`} spinning={loading}> </Spin>
								</div>
							 : <div className="hrm-wea-alert-page">
									<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@xyax2j`}>
							            <div style={{color: '#000'}}>
							                {i18n.message.authFailed()}
							            </div>
                        		  	</WeaAlertPage>
                        		</div>
					}
                </div>
			)
		} else {
			return (
				<div>
					<Header ecId={`${this && this.props && this.props.ecId || ''}_Header@ztudju`}>
						<Content ecId={`${this && this.props && this.props.ecId || ''}_Content@i5pcg6`} />
					</Header>
					<MainDialog ecId={`${this && this.props && this.props.ecId || ''}_MainDialog@s6kvds`} />
				</div>
			)
		}
	}


}