import React from 'react'
import {
	inject,
	observer,
} from 'mobx-react'
import {
	WeaAlertPage,
	WeaLeftRightLayout
} from 'ecCom'
import {
	Spin,
} from 'antd'
import {
	i18n
} from '../../public/i18n';

import '../../style/salaryItemsSet.css'

import Header from './Header';
import Search from './Search';
import LeftTree from './LeftTree';
import MainTableInfo from './MainTableInfo';
import MainDialog from './MainDialog';
import SubDialog from './SubDialog';

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

	componentWillMount() {
		let bool = window.location.href.indexOf('/spa/hrm/engine.html') > -1;
		if (bool) {
			document.title = i18n.module.wageSetting();
		}
	}

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

	componentDidMount() {
		this.init();
	}

	init() {
		const {
			hrmSalaryItemsSet
		} = this.props, {
			getAuth,
			forceLeftTreeRefresh,
		} = hrmSalaryItemsSet;

		getAuth();
		forceLeftTreeRefresh()
	}

	componentWillUnmount() {
		const {
			hrmSalaryItemsSet
		} = this.props, {
			closeAuth
		} = hrmSalaryItemsSet;

		closeAuth();
	}

	render() {
		const {
			hrmSalaryItemsSet
		} = this.props, {
			main,
			leftTree,
		} = hrmSalaryItemsSet, {
			authorized,
			loading
		} = main, {
			triggerRefresh
		} = leftTree;

		if (!authorized) {
			return (
				<div style={{height: '100%'}}>
					{loading ?  <div className='hrm-loading-center'>
									<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@w6u58w`} spinning={loading} size='large'></Spin>
								</div>
						     :	<div className="hrm-wea-alert-page">
		                			<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@tw9w9g`}>
						                <div style={{ color: '#000' }}>
						                    {i18n.message.authFailed()}
						                </div>
		                      		</WeaAlertPage>
	                        	</div>
	                }	
                </div>
			)
		} else {
			return (
				<div>
					<Header ecId={`${this && this.props && this.props.ecId || ''}_Header@hluakb`}>
							<WeaLeftRightLayout ecId={`${this && this.props && this.props.ecId || ''}_WeaLeftRightLayout@dwvwbg`} 
							    isNew={true}
							    leftCom={<LeftTree ecId={`${this && this.props && this.props.ecId || ''}_LeftTree@qk6csp`} triggerRefresh={triggerRefresh}/>}
							>
								<Search ecId={`${this && this.props && this.props.ecId || ''}_Search@bemdbu`} />
								<MainTableInfo ecId={`${this && this.props && this.props.ecId || ''}_MainTableInfo@kzpk4x`} />
							</WeaLeftRightLayout>
					</Header>
					<MainDialog ecId={`${this && this.props && this.props.ecId || ''}_MainDialog@4vewzl`} />
					<SubDialog ecId={`${this && this.props && this.props.ecId || ''}_SubDialog@76myyn`} />
				</div>
			)
		}
	}


}