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('hrmHolidayType')
@observer
export default class HolidayType extends React.Component {
	constructor(props) {
		super(props);
	}

	componentWillMount() {
		const {
			hrmHolidayType: store
		} = this.props;

		store.getPermissionInfo();
	}

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

	componentDidMount() {
		this.init();
	}

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

		store.getRightMenu();
		store.getSearchForm();
		store.setShowSearchAd(false);
	}

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

		if (!hasRight) {
			return loading ? <Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@neqbar`} size='lg'/> : <AlertPage ecId={`${this && this.props && this.props.ecId || ''}_AlertPage@6d831k`} />
		}
		return (
			<div>
				<Top ecId={`${this && this.props && this.props.ecId || ''}_Top@8fldpk`} store={store}/>
				<Dialog ecId={`${this && this.props && this.props.ecId || ''}_Dialog@cxgmn0`} store={store}/>
			</div>
		);
	}
}