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

@inject('hrmWorkingDayAdjust')

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

	componentDidMount() {
		this.init();
	}

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

	init = () => {
		const {
			hrmWorkingDayAdjust: store
		} = this.props;
		const {
			checkAuthorized,
			initData
		} = store;
		checkAuthorized('schedule/hrmPubHoliday', null, initData);
	}

	render() {
		const {
			hrmWorkingDayAdjust: store
		} = this.props;
		const {
			containerInitFinished,
			topBtnAndMenu,
			displayType,
			spinning
		} = store;
		const {
			btns,
			menus
		} = topBtnAndMenu();
		const topProps = {
			title: i18n.module.workingDayAdjust(),
			icon: <i className='icon-coms-hrm'/>,
			iconBgcolor: '#217346',
			showDropIcon: true,
			buttons: btns,
			dropMenuDatas: menus
		}
		return (
			<div className="hrm_module_container workingDayAdjust">
			{
				containerInitFinished.init && containerInitFinished.authorized &&
				<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@wf1hos`} spinning={spinning}>
					<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@s4h8fi`} {...topProps}>
						<ConditionBar ecId={`${this && this.props && this.props.ecId || ''}_ConditionBar@f76vi6`} store={store} />
						<div className='tabPane'>
							<WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@k3y51l`} datas={menus}>
								<Content ecId={`${this && this.props && this.props.ecId || ''}_Content@je127o`} store={store} />
							</WeaRightMenu>
						</div>
					</WeaTop>
				</Spin>
			}
			{
				containerInitFinished.init && !containerInitFinished.authorized && 
              	<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@2xdgfw`}>
                  	<div style={{ color: '#000' }}>{i18n.message.authFailed()}</div>
              	</WeaAlertPage>
			}
			</div>
		)
	}
}