import {
	inject,
	observer,
} from 'mobx-react'
import {
	toJS
} from 'mobx'
import {
	WeaTableNew
} from 'comsMobx'
import {
	Modal,
	message
} from 'antd'
import {
	i18n
} from '../../public/i18n';
const WeaTable = WeaTableNew.WeaTable;
const confirm = Modal.confirm;

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

	log = () => {
		window.setLogViewProps({
			logSmallType: '3037',
		});
	}

	new = () => {
		const {
			hrmTrainActivity
		} = this.props, {
			openMainDialog
		} = hrmTrainActivity;

		openMainDialog();
	}

	batchDelete = () => {
		this.showConfirm();
	}

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

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

	showConfirm = () => {
		const {
			hrmTrainActivity
		} = this.props, {
			refreshTable
		} = hrmTrainActivity;

		let _this = this;
		confirm({
			title: i18n.confirm.defaultTitle(),
			content: i18n.confirm.delete(),
			okText: i18n.button.ok(),
			cancelText: i18n.button.cancel(),
			onOk() {
				_this.onOk()
			},
			onCancel() {
				refreshTable('main');
				return false
			},
		});
	}

	onOk = () => {
		const {
			hrmTrainActivity
		} = this.props, {
			deleteTableInfo
		} = hrmTrainActivity;

		deleteTableInfo();
	}

	onOperatesClick = (record, rowIndex, operate) => {
		const {
			hrmTrainActivity
		} = this.props, {
			setSelectRowKey,
			setIndex,
			openMainDialog,
		} = hrmTrainActivity, {
			randomFieldId
		} = record, {
			index
		} = operate;

		setSelectRowKey(randomFieldId, 'main');

		setIndex(index);

		switch (index) {
			case '7':
				this.showConfirm();
				break;
			case '8':
				window.setLogViewProps({
					logSmallType: '3037',
					targetId: randomFieldId,
				});
				break;
			default:
				openMainDialog()
		}

	}

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

		return (
			<WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@oyjgb3`} 
			 	comsWeaTableStore={tableStore}
			 	hasOrder={true}
			 	needScroll={true}
			 	onOperatesClick={(record, rowIndex, operate) => this.onOperatesClick(record, rowIndex, operate)}
			/>
		)

	}
}