import { createElement as _createElement } from "react";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from "react";
import { useTable } from "react-table";
import "./style.scss";
import { Loader } from "../..";
import clsx from "clsx";
const CompanyViewFinancialGenericTable = ({ data, headers, isError = false, isLoading = false, }) => {
    const columns = React.useMemo(() => [...headers], []);
    const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable({ columns, data });
    const className = clsx({
        [``]: isError,
        [`CompanyViewFinancialGenericTableWrapper`]: !isError || isLoading,
    });
    return (_jsx("div", { className: className, children: isLoading ? (_jsx("div", { className: "GenericTableLoading", children: _jsx(Loader, { height: "32", width: "32", type: "tailSpin" }) })) : isError ? (_jsx("div", { className: "GenericTableError", children: "NOT AVAILABLE" })) : (_jsx("div", { children: _jsxs("table", { className: "GenericTable", ...getTableProps(), children: [_jsx("thead", { children: headerGroups.map((headerGroup) => (_jsx("tr", { ...headerGroup.getHeaderGroupProps(), children: headerGroup.headers.map((column) => (_jsx("th", { ...column.getHeaderProps(), children: column.render("Header") }))) }))) }), _jsx("tbody", { ...getTableBodyProps(), children: rows.map((row) => {
                            prepareRow(row);
                            return (_createElement("tr", { ...row.getRowProps(), key: `${row.original.publicIdentifier}${row.original.isSelected}` }, row.cells.map((cell) => {
                                return (_jsx("td", { ...cell.getCellProps(), children: cell.render("Cell") }));
                                //   }
                            })));
                        }) })] }) })) }));
};
export default CompanyViewFinancialGenericTable;
