import '../../style/privacySetting.less';
import React, {
	Component
} from 'react';
import {
	inject,
	observer
} from 'mobx-react';
import {
	WeaTop,
	WeaAlertPage,
	WeaRightMenu,
	WeaNewScroll,
	WeaDialog
} from 'ecCom';
import {
	Spin
} from 'antd';
import Setting from './Setting';
import {
	i18n
} from '../../public/i18n';

@inject('hrmPrivacySetting')

@observer
export default class PrivacySetting extends Component {
	constructor(props) {
		super(props);
	}

	componentDidMount() {
		this.init();
	}

	componentWillUnmount() {}

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

	init = () => {
		const {
			hrmPrivacySetting: store
		} = this.props;
		const {
			checkAuthorized,
			initData
		} = store;
		checkAuthorized('privacySetting', null, initData);
	}

	render() {
		const {
			hrmPrivacySetting: store
		} = this.props;
		const {
			containerInitFinished,
			topBtnAndMenu,
			spinning,
			dialogParams,
			getDialogOpButtons
		} = store;
		const {
			btns,
			menus
		} = topBtnAndMenu();
		const topProps = {
			title: i18n.module.privacySetting(),
			icon: <i className='icon-coms-hrm'/>,
			iconBgcolor: '#217346',
			showDropIcon: true,
			buttons: btns,
			dropMenuDatas: menus
		}
		const dProps = {
			...dialogParams,
			buttons: getDialogOpButtons(),
			className: "hrmDialog"
		}
		return (
			<div className="hrm_module_container privacySetting">
			{
				containerInitFinished.init && containerInitFinished.authorized &&
				<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@8o1jk4`} spinning={spinning}>
					<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@a0sj6p`} {...topProps}>
						<WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@z2ozth`} height={'100%'}>
							<WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@7nlsyt`} datas={menus}>
								<Setting ecId={`${this && this.props && this.props.ecId || ''}_Setting@nh6sx3`} store={store}/>
							</WeaRightMenu>
						</WeaNewScroll>
					</WeaTop>
				</Spin>
			}
			{
				containerInitFinished.init && !containerInitFinished.authorized && 
              	<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@yoxtaf`}>
                  	<div style={{ color: '#000' }}>{i18n.message.authFailed()}</div>
              	</WeaAlertPage>
			}
			<WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@pwaxk1`} {...dProps}>
			{dProps.coms}
			</WeaDialog>
			</div>
		)
	}
}