import '../../style/paidLevel.less';
import React, {
	Component
} from 'react';
import {
	inject,
	observer
} from 'mobx-react';
import {
	WeaTop,
	WeaAlertPage,
	WeaRightMenu,
	WeaLeftRightLayout,
	WeaSearchGroup,
	WeaNewScroll
} from 'ecCom';
import Tabs from '../../coms/Tabs';
import OrganizationTree from '../../coms/OrganizationTree';
import DataList from './DataList';
import {
	i18n
} from '../../public/i18n';


@inject('hrmPaidLevelTimeSetting')
@observer
export default class PaidLevelTimeSetting 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 {
			hrmPaidLevelTimeSetting: store
		} = this.props;
		const {
			checkAuthorized,
			initData
		} = store;
		checkAuthorized('paidleave', {
			type: 'list'
		}, initData);
	}

	render() {
		const {
			hrmPaidLevelTimeSetting: store
		} = this.props;
		const {
			containerInitFinished,
			topBtnAndMenu,
			orgTreeProps,
			refreshData,
			onDateRangeChangeHandle,
			createdateselect,
			selectedSubCompany,
			tabConfig,
			refreshTab,
			formTarget
		} = store;
		const {
			btns,
			menus
		} = topBtnAndMenu();
		const {
			conditionForm: form,
			conditionFormFields: fields
		} = formTarget;
		const tabProps = {
			tabConfig: tabConfig,
			activeTabInfo: {
				activeTabKey: tabConfig.activeTabKey,
				activeTabIndex: 0
			},
			rightMenu: menus,
			store: store,
			conditionForm: form,
			conditionFormFields: fields,
		}
		let title = i18n.module.paidLevelTimeSetting();
		if (selectedSubCompany != null)
			title += ` - ${selectedSubCompany.name}`;
		//<SearchCondition store={store} value={store.toJS(createdateselect)} onChangeHandle={onDateRangeChangeHandle}/>
		return (
			<div className="hrm_module_container paidLevelTimeSetting">
				{
					containerInitFinished.init && containerInitFinished.authorized &&
					<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@hq4pxs`}
						title={title}
						icon={<i className='icon-coms-hrm'/>}
						iconBgcolor='#217346'
						showDropIcon={true}
						buttons={btns}
						dropMenuDatas={menus}
					>
						<WeaLeftRightLayout ecId={`${this && this.props && this.props.ecId || ''}_WeaLeftRightLayout@us3b4f`} leftCom={<OrganizationTree ecId={`${this && this.props && this.props.ecId || ''}_OrganizationTree@r4flk3`} {...orgTreeProps} ref='orgTree'/>}>
							<Tabs ecId={`${this && this.props && this.props.ecId || ''}_Tabs@1i7bn6`} {...tabProps}>
								<DataList ecId={`${this && this.props && this.props.ecId || ''}_DataList@4s7739`}/>
							</Tabs>
						</WeaLeftRightLayout>
					</WeaTop>
				}
				{
					containerInitFinished.init && !containerInitFinished.authorized && 
	              	<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@6cj191`}>
	                  	<div style={{ color: '#000' }}>{i18n.message.authFailed()}</div>
	              	</WeaAlertPage>
				}
			</div>
		)
	}
}