import React, { Component } from 'react';
import { Table } from 'antd';
import './index.less';

class TableLayout extends Component {
  render() {
    const {
      select = false,
      columns,
      rowKey = 'id',
      list = [],
      pagination,
      loading,
      onChange,
      selectedKeys,
    } = this.props;
    let rowSelection = null;
    if (select) {
      rowSelection = {
        onChange: (selectedRowKeys, selectedRows) => this.props.onSelect(selectedRowKeys, selectedRows),
        selectedRowKeys: selectedKeys,
      };
    }
    return (
      <div className="table-layout">
        <Table
          columns={columns}
          bordered
          rowSelection={rowSelection}
          rowKey={record => record[rowKey]}
          dataSource={list}
          pagination={pagination}
          loading={loading}
          onChange={onChange}
        />
      </div>
    );
  }
}

export default TableLayout;
