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

@inject('hrmNewHolidayRule')
@observer
export default class NewHolidayRule extends React.Component {
	constructor(props) {
		super(props);
	}

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

	componentDidMount() {
		this.init();
	}

	init = () => {
		const {
			hrmNewHolidayRule: store
		} = this.props;

		const callback = () => {
			store.getRightMenu();
			store.getSearchForm();
			store.setShowSearchAd(false);
		}

		store.getPermissionInfo(callback);
	}

	render() {
		const {
			hrmNewHolidayRule: store
		} = this.props, {
			permission,
		} = store, {
			hasRight,
			loading
		} = permission;

		if (!hasRight) {
			return loading ? <Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@2pxusp`} size='lg'/> : <AlertPage ecId={`${this && this.props && this.props.ecId || ''}_AlertPage@45x72h`} />
		}
		return (
			<div>
				<Top ecId={`${this && this.props && this.props.ecId || ''}_Top@g08ae3`} store={store}/>
				<Dialog ecId={`${this && this.props && this.props.ecId || ''}_Dialog@d6pkqi`} store={store}/>
			</div>
		);
	}
}