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

	componentWillMount() {
		this.props.hrmAttendanceRpSharingSetting.reset();
	}

	componentDidMount() {
		this.props.hrmAttendanceRpSharingSetting.getPermissionInfo();
	}

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

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

		if (!hasRight) {
			return loading ? <Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@gctjk1`} size='lg'/> : <AlertPage ecId={`${this && this.props && this.props.ecId || ''}_AlertPage@4eqg7l`} />
		} else {
			return (
				<div>
					<Top ecId={`${this && this.props && this.props.ecId || ''}_Top@1o9gd2`} />
					<Dialog ecId={`${this && this.props && this.props.ecId || ''}_Dialog@r3bfm5`} />
				</div>
			)
		}
	}
}