import '../../../style/worktime.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 DataList from './DataList';
import {
	i18n
} from '../../../public/i18n';

@inject('hrmScheduleWorkTime')

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

	componentDidMount() {
		this.init();
	}

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

	init = () => {
		const {
			hrmScheduleWorkTime: store
		} = this.props;
		const {
			checkAuthorized,
			initData
		} = store;
		checkAuthorized('scheduleworktime', null, initData);
	}

	render() {
		const {
			hrmScheduleWorkTime: store
		} = this.props;
		const {
			containerInitFinished,
			topBtnAndMenu,
			formTarget,
			tabConfig
		} = 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 worktime">
				{
					containerInitFinished.init && containerInitFinished.authorized &&
					<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@8tudy4`}
						title={i18n.module.workTime()}
						icon={<i className='icon-coms-hrm'/>}
						iconBgcolor='#217346'
						showDropIcon={true}
						buttons={btns}
						dropMenuDatas={menus}
					>
						<Tabs ecId={`${this && this.props && this.props.ecId || ''}_Tabs@qycse9`} {...tabProps}>
							<DataList ecId={`${this && this.props && this.props.ecId || ''}_DataList@d5xfxe`} store={store} rightMenu={menus}/>
						</Tabs>
					</WeaTop>
				}
				{
					containerInitFinished.init && !containerInitFinished.authorized && 
	              	<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@jx29mz`}>
	                  	<div style={{ color: '#000' }}>{i18n.message.authFailed()}</div>
	              	</WeaAlertPage>
				}
			</div>
		)
	}
}