import Button from '../../button';
import React from 'react';
import ReactDOM from 'react-dom';
import Table from '..';
const onRowClick = function (record, index, e) {
    console.log(record, index, e);
}, dataSource = () => {
    const result = [];
    for (let i = 0; i < 5; i++) {
        result.push({
            title: {
                name: `Quotation for 1PCS Nano ${3 + i}.0 controller compatible`,
            },
            id: 100306660940 + i,
            time: 2000 + i,
        });
    }
    return result;
};
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.state = {
            dataSource: dataSource(),
        };
        this.onAdd = () => {
            const { dataSource } = this.state;
            dataSource.push({
                title: {
                    name: 'Quotation for 1PCS Nano controller compatible',
                },
                id: Date.now(),
                time: 2000,
            });
            this.setState({
                dataSource,
            });
        };
        this.onRemove = id => {
            const { dataSource } = this.state;
            let index = -1;
            dataSource.forEach((item, i) => {
                if (item.id === id) {
                    index = i;
                }
            });
            if (index !== -1) {
                dataSource.splice(index, 1);
                this.setState({
                    dataSource,
                });
            }
        };
    }
    render() {
        const renderOper = (value, index, record) => {
            return (React.createElement("a", { onClick: this.onRemove.bind(this, record.id) },
                "Remove(",
                record.id,
                ")"));
        };
        return (React.createElement("div", null,
            React.createElement("p", null,
                React.createElement(Button, { onClick: this.onAdd }, "Add Item")),
            React.createElement(Table, { dataSource: this.state.dataSource, onRowClick: onRowClick },
                React.createElement(Table.Column, { title: "Id", dataIndex: "id" }),
                React.createElement(Table.Column, { title: "Title", dataIndex: "title.name" }),
                React.createElement(Table.Column, { title: "Time", dataIndex: "time" }),
                React.createElement(Table.Column, { cell: renderOper, width: "20%" }))));
    }
}
ReactDOM.render(React.createElement(App, null), document.getElementById('table-demo-11'));
