import {
	inject,
	observer
} from 'mobx-react';
import {
	WeaTableNew
} from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;

@inject('hrmHolidySettingNew')
@observer
class Table extends React.Component {
	constructor(props) {
		super(props);
	}

	reRenderColumns = (columns) => {
		columns.map(c => {
			if (c.dataIndex === 'holidayDate') {
				c.render = (t, r) => {
					const {
						holidayDatespan,
						randomFieldId
					} = r;

					return <a onClick={() => this.handleClick(randomFieldId) }>{holidayDatespan}</a>
				}
			}
		});
	}

	handleClick = (randomFieldId) => {
		const funcs = ['setOperatedRowId', 'setDialogType', 'openDialog'],
			params = [randomFieldId, '2', ''];

		funcs.map((func, index) => {
			this.props.hrmHolidySettingNew[func](params[index])
		});
	}

	render() {
		const {
			table,
			tableProps
		} = this.props.hrmHolidySettingNew;

		return (
			<WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@mwpapv`} 
				{...table}
				{...tableProps}
				getColumns={this.reRenderColumns}
			/>
		);
	}
}

export default Table