import PropTypes from 'prop-types';
import React from 'react';
import ReactDOM from 'react-dom';
import Table from '..';
const { Header, Cell } = Table;
const dataSource = () => {
    const result = [];
    for (let i = 0; i < 5; i++) {
        result.push({
            title: `Quotation for 1PCS Nano ${3 + i}.0 controller compatible`,
            id: 100306660940 + i,
            time: 2000 + i,
        });
    }
    return result;
};
const AppHeader = (props, context) => {
    const { columns } = props;
    const { onChange } = context;
    const length = columns[columns.length - 1].length;
    return (React.createElement(Header, Object.assign({}, props),
        React.createElement("tr", null,
            React.createElement(Cell, { colSpan: length },
                React.createElement("a", { onClick: () => onChange(true), href: "javascript:;" }, "Select all"),
                React.createElement("span", { style: { marginRight: 20 } }),
                React.createElement("a", { onClick: () => onChange(false), href: "javascript:;" }, "Unselect all")))));
};
AppHeader.contextTypes = {
    onChange: PropTypes.func,
};
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.state = {
            selectedKeys: [],
        };
        this.dataSource = dataSource();
        this.onChange = checked => {
            let selectedKeys = [];
            if (checked) {
                selectedKeys = this.dataSource.map(item => item.id);
            }
            this.onRowChange(selectedKeys);
        };
        this.onRowChange = selectedKeys => {
            this.setState({
                selectedKeys,
            });
        };
    }
    getChildContext() {
        return {
            onChange: this.onChange,
        };
    }
    render() {
        return (React.createElement("span", null,
            React.createElement(Table, { dataSource: this.dataSource, 
                // @ts-ignore
                components: {
                    Header: AppHeader,
                }, rowSelection: {
                    selectedRowKeys: this.state.selectedKeys,
                    onChange: this.onRowChange,
                } },
                React.createElement(Table.Column, { title: "Id", dataIndex: "id" }),
                React.createElement(Table.Column, { title: "Title", dataIndex: "title" }),
                React.createElement(Table.Column, { title: "Time", dataIndex: "time" }))));
    }
}
App.childContextTypes = {
    onChange: PropTypes.func,
}; /* eslint-disable react/no-multi-comp,react/prop-types */
ReactDOM.render(React.createElement(App, null), document.getElementById('table-demo-20'));
