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

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

import Top from './Top';
import Dialog from './Dialog';

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

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

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

		['resetStorePropertys', 'setPageConfig', 'getPermissionInfo'].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@wczjmo`} size='lg'/> : <AlertPage ecId={`${this && this.props && this.props.ecId || ''}_AlertPage@7wai04`} />
		} else {
			return (
				<div>
					<Top ecId={`${this && this.props && this.props.ecId || ''}_Top@y19d18`} />
					<Dialog ecId={`${this && this.props && this.props.ecId || ''}_Dialog@f3uah2`} />
				</div>

			)
		}
	}
}

export default HolidayRule