import React from 'react';
import {
	observer,
	inject
} from 'mobx-react';
import {
	AlertPage,
	Loading,
} from '../../public/learn';

import * as asyncFetch from '../../apis/travelRule';

import Top from './Top';

@inject('commonStore')
@inject('hrmTravelRule')
@observer
class TravelRule extends React.Component {
	constructor(props) {
		super(props);
	}

	componentWillMount() {
		const {
			pageConfig,
		} = this.props.hrmTravelRule;

		const params = {
			...pageConfig,
			customizedStore: this.props.hrmTravelRule,
		};

		['resetStorePropertys', 'setPageConfig', 'getPermissionInfo', 'refreshPage'].map((f, i) => {
			this.props.commonStore[f](i === 1 && params);
		});
	}

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

	render() {
		const {
			commonStore,
		} = this.props, {
			pageAccessPermission
		} = commonStore, {
			hasRight,
			loading
		} = pageAccessPermission;

		if (!hasRight) {
			return loading ? <Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@kgtf8e`} size='lg'/> : <AlertPage ecId={`${this && this.props && this.props.ecId || ''}_AlertPage@g0rldu`} />
		} else {
			return (
				<Top ecId={`${this && this.props && this.props.ecId || ''}_Top@rwao8k`} />
			)
		}
	}
}

export default TravelRule