import React, {
	Component
} from 'react';
import {
	inject,
	observer
} from 'mobx-react';
import {
	WeaTop,
	WeaAlertPage,
	WeaRightMenu,
	WeaSearchGroup,
	WeaNewScroll
} from 'ecCom';
import FormInfo from '../../coms/FormInfo';
import ImportResource from '../importresource/Import';
import {
	i18n
} from '../../public/i18n';

@inject('hrmImportExternalAttendance')
@inject('hrmImportResource')
@observer
export default class ImportExtenalAttendanceData extends Component {
	constructor(props) {
		super(props);
	}

	componentDidMount() {
		this.init();
	}

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

	componentWillUnmount() {
		const {
			hrmImportExternalAttendance: store,
		} = this.props;
		store.resetImportResource();
	}

	init = () => {
		const {
			hrmImportExternalAttendance: store,
			hrmImportResource
		} = this.props;
		const {
			checkAuthorized,
			initData
		} = store;
		store.setImportResource(hrmImportResource);
		checkAuthorized('schedulesignimport', null, initData);
	}

	render() {
		const {
			hrmImportExternalAttendance: store
		} = this.props;
		const {
			containerInitFinished,
			topBtnAndMenu,
			message
		} = store;
		const {
			btns,
			menus
		} = topBtnAndMenu();
		let children = [];
		if (message.length > 0) {
			message.map(m => {
				children.push(<div>{m}</div>)
			})
		}
		const msgCom = <div>{children}</div>;

		return (
			<div className="hrm_module_container">
				{
					containerInitFinished.init && containerInitFinished.authorized &&
					<WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@g1r83j`}
						title={i18n.module.importExternalDataAttendance()}
						icon={<i className='icon-coms-hrm'/>}
						iconBgcolor='#217346'
						showDropIcon={true}
						buttons={btns}
						dropMenuDatas={menus}
					>
						<WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@cit4pv`} height={'100%'}>
							<WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@rjg3t4`} datas={menus}>
								<ImportResource ecId={`${this && this.props && this.props.ecId || ''}_ImportResource@lnp5b3`}/>
								{
									message.length > 0 && 
									<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@b0cjz0`} col={1} showGroup={true} title={i18n.label.promptInformation()} items={[{com:msgCom}]}/>
								}
							</WeaRightMenu>
						</WeaNewScroll>
					</WeaTop>
				}
				{
					containerInitFinished.init && !containerInitFinished.authorized && 
	              	<WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@ll3zl3`}>
	                  	<div style={{ color: '#000' }}>{i18n.message.authFailed()}</div> 
	                </WeaAlertPage>
				} 
			</div>
		)
	}
}