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

@inject('hrmScheduleShiftsSetting')

@observer
export default class ScheduleShiftsSetting 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 {
			hrmScheduleShiftsSetting: store
		} = this.props;
		const {
			checkAuthorized,
			initData
		} = store;
		checkAuthorized('scheduleshiftsset', null, initData, null, true);
	}

	render() {
		const {
			hrmScheduleShiftsSetting: store
		} = this.props;
		const {
			containerInitFinished,
			topBtnAndMenu,
			formTarget,
			tabConfig,
			orgTreeProps,
			refreshMainTab
		} = 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,
		}

		return (
			<div className="hrm_module_container shiftsSetting">
				{
					containerInitFinished.init && containerInitFinished.authorized &&
					<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@mln3lz`}
						title={i18n.module.shiftsSetting()}
						icon={<i className='icon-coms-hrm'/>}
						iconBgcolor='#217346'
						showDropIcon={true}
						buttons={btns}
						dropMenuDatas={menus}
					>
						{
							containerInitFinished.detachable ? 
							<WeaLeftRightLayout ecId={`${this && this.props && this.props.ecId || ''}_WeaLeftRightLayout@vohz25`} leftCom={<OrganizationTree ecId={`${this && this.props && this.props.ecId || ''}_OrganizationTree@jy7cs1`} {...orgTreeProps} ref='orgTree'/>}>
								<Tabs ecId={`${this && this.props && this.props.ecId || ''}_Tabs@je8pma`} {...tabProps}>
									<Setting ecId={`${this && this.props && this.props.ecId || ''}_Setting@v0vycs`}/>
								</Tabs>
							</WeaLeftRightLayout>
							:
							<Tabs ecId={`${this && this.props && this.props.ecId || ''}_Tabs@88ehch`} {...tabProps}>
								<Setting ecId={`${this && this.props && this.props.ecId || ''}_Setting@1q7nbj`}/>
							</Tabs>
						}
					</WeaTop>
				}
				{
					containerInitFinished.init && !containerInitFinished.authorized && 
	              	<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@nk8zto`}>
	                  	<div style={{ color: '#000' }}>{i18n.message.authFailed()}</div>
	              	</WeaAlertPage>
				}
			</div>
		)
	}
}