import React from 'react' import { useMobileMediaQuery } from '../../../Media' import { Table } from '../../../Table/Table' import { Loader } from '../../../Loader/Loader' import { Pagination } from '../../../Pagination/Pagination' import { Props } from './TableContent.types' import './TableContent.css' const TABLE_SIBLINGS_RANGE_MOBILE = 0 const TABLE_SIBLINGS_RANGE_DESKTOP = 1 export const ROWS_PER_PAGE = 10 const TableContent = (props: Props) => { const { empty, data, isLoading, totalPages, activePage = 1, setPage, total, rowsPerPage = ROWS_PER_PAGE, hasHeaders = false, customHeaders = {}, i18n } = props const isMobile = useMobileMediaQuery() const attributes = data.length > 0 ? Object.keys(data[0]) : null const hasPagination = totalPages && totalPages > 1 return (
{isLoading ? (
) : attributes ? ( { <> {attributes.map((attr) => ( {customHeaders[attr] ? customHeaders[attr] : attr} ))} {data?.map((data: unknown, index) => ( {attributes.map((attr: string) => ( {data[attr]} ))} ))} }
) : ( empty() )} {hasPagination && total && props.activePage !== undefined ? (
{`${i18n.sortBy.showing} ${ (activePage - 1) * rowsPerPage + 1 }-${Math.min(activePage * rowsPerPage, total)} ${ i18n.sortBy.of } ${total}`} setPage && setPage(+props.activePage) } firstItem={null} lastItem={null} />
) : null}
) } TableContent.defaultProps = { i18n: { sortBy: { showing: 'Showing', of: 'of' } } } export default React.memo(TableContent)