import {
	inject,
	observer,
} from 'mobx-react'
import {
	toJS
} from 'mobx'
import {
	WeaRightMenu,
} from 'ecCom'
import {
	WeaTableNew
} from 'comsMobx'
import {
	i18n
} from '../../public/i18n';
const WeaTable = WeaTableNew.WeaTable;

@inject('hrmTrainActivity')
@observer
export default class ThirdTable extends React.Component {
	constructor(props) {
		super(props);
	}

	componentWillUnmount() {
		const {
			hrmTrainActivity
		} = this.props, {
			resetTableSelectedKeys
		} = hrmTrainActivity;

		resetTableSelectedKeys();
	}

	getDropMenuDatas = () => {
		const {
			hrmTrainActivity,
		} = this.props, {
			subDialogmenu,
			thirdTable,
		} = hrmTrainActivity, {
			rightMenu
		} = subDialogmenu;

		const len = thirdTable.tableStore.selectedRowKeys.length;

		let menus = [];
		toJS(rightMenu).map((item, index) => {
			let obj = {
				key: item.menuFun,
				icon: <i className={`${item.menuIcon}`}/>,
				content: item.menuName,
			}
			if (item.menuFun == 'log' || item.menuFun == 'collection' || item.menuFun == 'help' || item.menuFun == 'pageAddress') {
				obj.disabled = true;
			}
			if (item.menuFun == 'join') {
				obj.disabled = len > 0 ? false : true;
			}
			menus.push(obj);
		})

		return menus;
	}

	handleMenuClick = (key) => {
		this[key] && this[key]();
	}

	join = () => {
		const {
			hrmTrainActivity
		} = this.props, {
			attend
		} = hrmTrainActivity;

		attend();
	}

	custom = () => {
		const {
			hrmTrainActivity
		} = this.props, {
			thirdTable,
		} = hrmTrainActivity, {
			tableStore
		} = thirdTable;

		tableStore.setColSetVisible(true);
		tableStore.tableColSet(true);
	}

	render() {
		const {
			hrmTrainActivity,
		} = this.props, {
			thirdTable,
		} = hrmTrainActivity, {
			tableStore
		} = thirdTable;

		return (
			<WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@cxqws5`} datas={this.getDropMenuDatas()} onClick={ key => this.handleMenuClick(key)}>
				<WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@037ef4`} 
				 	comsWeaTableStore={tableStore}
				 	hasOrder={true}
				 	needScroll={true}
				/>
			</WeaRightMenu>
		)

	}
}