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

@observer
export default class Table extends React.Component {
	constructor(props) {
		super(props);
	}

	reRenderColumns = (columns, store) => {
		const {
			edit
		} = store;

		columns.map(c => {
			if (c.dataIndex === 'lastname') {
				c.render = function(text, record) {
					return <a onClick={() => edit(id)}>{text}</a>
				}
			}
		});
	}

	onOperatesClick = (record, rIndex, operate, store) => {
		const {
			randomFieldId
		} = record, {
			index
		} = operate;

		const {
			del,
			edit
		} = store;

		if (index === '0') {
			edit(randomFieldId);
		} else {
			del(randomFieldId);
		}
	}

	render() {
		const {
			store
		} = this.props, {
			TABLE,
			table
		} = store;

		return (
			<WeaTable 
				{...TABLE}
				{...table}
				getColumns={columns => this.reRenderColumns(columns,store)}
				onOperatesClick={(record, index, operate) => this.onOperatesClick(record,index, operate,store)}
			/>
		);
	}
}