
/**
 * Component used for Table 
 * 
 * @author Ashique
 * 
 * Ensure to follow a minimal standard
 */

import React, { useState, useEffect } from 'react';

import { Space, Table } from 'antd';

import { ExportReactCSV } from '../../../modules/generic/generic-list/ExportReactCSV';

import { getExportData } from '../../../utils/generic/generic.utils';


import './basic-table.scss';

/**
 * Basic Tabular
 *
 * @param {*} param0
 * @returns
 */
export default function BasicTable({ result, styles = {}, ...props }) {

    // Get the columns
    let columns = [];

    if (result[0]) {

        columns = Object.keys(result[0]).map(column => {
            return {
                // title : <div style={{ textAlign: styles[column].textAlign }}>{column}</div>,
                title: column,
                dataIndex: column,
                key: column,
                render: (text, record) => {

                    return <div className='table-field' style={styles[column]}>{text}</div>;
                },
            };
        });

    } else {

    }

    // Get the export data 
    // let exportData = getExportData(result, columns);

    return (

        <>

            <div className="table-actions">

                {/*table data export to csc component*/}
                {/* {result && <ExportReactCSV csvData={exportData} />} */}

            </div>


            <Table
                className="table-exportable"
                scroll={{ x: true }}
                // loading={loading}
                size="small"
                rowKey={(record) => record.id}
                dataSource={result}
                columns={columns}
                pagination={false}
            ></Table>


        </>
    );
}






/**
 *
 * @param {*} records
 * @param {*} columns
 * @returns
 */
// export function getExportData(records = [], columns) {

//     return records.map((ele, index) => {

//         let entry = {
//             'Sl No': index + 1
//         };

//         columns.forEach((column, index) => {


//             entry[column.title] = ele[column.field];

//         })

//         return entry;

//     })
// }