import '../../../style/paidLeaveSetting.less';
import React, {
	Component
} from 'react';
import {
	inject,
	observer
} from 'mobx-react';
import {
	WeaTop,
	WeaAlertPage,
	WeaRightMenu,
	WeaLeftRightLayout
} from 'ecCom';
import {
	Spin
} from 'antd';
import OrganizationTree from '../../../coms/OrganizationTree';
import Tabs from '../../../coms/Tabs';
import TabPane from './TabPane';
import {
	i18n
} from '../../../public/i18n';

@inject('hrmAnnualSetting')
@inject('hrmImportResource')

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

	componentDidMount() {
		this.init();
	}

	componentWillReceiveProps(nextProps) {
		if (this.props.location.key !== nextProps.location.key) {
			this.init();
			this.refs.orgTree && this.refs.orgTree.refs.tree.fetchData();
		}
	}

	init = () => {
		const {
			hrmAnnualSetting: store,
			hrmImportResource
		} = this.props;
		const {
			checkAuthorized,
			initData,
			setImportStore
		} = store;
		setImportStore(hrmImportResource);
		checkAuthorized('annualmanager', {
			type: 'AnnualLeave'
		}, initData);
	}

	render() {
		const {
			hrmAnnualSetting: store
		} = this.props;
		const {
			containerInitFinished,
			topBtnAndMenu,
			orgTreeProps,
			selectedSubCompany,
			spinning,
			refreshTopBtn
		} = store;
		const {
			btns,
			menus
		} = topBtnAndMenu();
		let title = i18n.module.annualSetting();
		if (selectedSubCompany != null && selectedSubCompany.name)
			title = `${title} - ${selectedSubCompany.name}`;
		const topProps = {
			title,
			icon: <i className='icon-coms-hrm'/>,
			iconBgcolor: '#217346',
			showDropIcon: true,
			buttons: btns,
			dropMenuDatas: menus
		}
		return (
			<div className="hrm_module_container paidLeaveSetting">
			{
				containerInitFinished.init && containerInitFinished.authorized &&
				<Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@thyto1`} spinning={spinning}>
				<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@qjlqda`} {...topProps}>
					<WeaLeftRightLayout ecId={`${this && this.props && this.props.ecId || ''}_WeaLeftRightLayout@otggrj`} leftCom={<OrganizationTree ecId={`${this && this.props && this.props.ecId || ''}_OrganizationTree@01n2ep`} {...orgTreeProps} ref='orgTree'/>}>
						<TabPane ecId={`${this && this.props && this.props.ecId || ''}_TabPane@stuz61`} store={store} rightMenu={menus}/>
					</WeaLeftRightLayout>
				</WeaTop>
				</Spin>
			}
			{
				containerInitFinished.init && !containerInitFinished.authorized && 
              	<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@s5aoro`}>
                  	<div style={{ color: '#000' }}>{i18n.message.authFailed()}</div>
              	</WeaAlertPage>
			}
			</div>
		)
	}
}