import '../../style/leaveType.less';
import React, {
	Component
} from 'react';
import {
	inject,
	observer
} from 'mobx-react';
import {
	WeaTop,
	WeaAlertPage,
	WeaRightMenu,
	WeaNewScroll,
	WeaTableEdit
} from 'ecCom';
import {
	i18n
} from '../../public/i18n';

@inject('hrmLeaveType')

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

	componentDidMount() {
		this.init();
	}

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

	init = () => {
		const {
			hrmLeaveType: store
		} = this.props;
		const {
			checkAuthorized,
			initData
		} = store;
		checkAuthorized('schedule/leaveType', null, initData);
	}

	render() {
		const {
			hrmLeaveType: store
		} = this.props;
		const {
			containerInitFinished,
			topBtnAndMenu,
			tableConfig,
			setTableRef,
			onRowSelect,
			getRowSelection,
			onDelete
		} = store;
		const {
			btns,
			menus
		} = topBtnAndMenu();
		const topProps = {
			title: i18n.module.leaveType(),
			icon: <i className='icon-coms-hrm'/>,
			iconBgcolor: '#217346',
			showDropIcon: true,
			buttons: btns,
			dropMenuDatas: menus
		}
		return (
			<div className="hrm_module_container leaveType">
			{
				containerInitFinished.init && containerInitFinished.authorized &&
				<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@t3uw9b`} {...topProps}>
					<WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@ev4cz4`} datas={menus}>
						<WeaTableEdit ecId={`${this && this.props && this.props.ecId || ''}_WeaTableEdit@m1b51s`} {...store.toJS(tableConfig)} deleteConfirm ref={ref => setTableRef(ref)} onRowSelect={onRowSelect} getRowSelection={getRowSelection} onDelete={onDelete}/>
					</WeaRightMenu>
				</WeaTop>
			}
			{
				containerInitFinished.init && !containerInitFinished.authorized && 
              	<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@wwzgjt`}>
                  	<div style={{ color: '#000' }}>{i18n.message.authFailed()}</div>
              	</WeaAlertPage>
			}
			</div>
		)
	}
}