import { ReactNode } from "react";
import {
ButtonGroup,
Center,
Flex,
HStack,
IconButton,
Link,
Select,
Table,
Tbody,
Td,
Text,
Th,
Thead,
Tr,
VStack,
} from "@chakra-ui/react";
import {
FiChevronsLeft,
FiChevronLeft,
FiChevronsRight,
FiChevronRight,
FiChevronDown,
FiChevronUp,
FiX,
} from "react-icons/fi";
import { TablePagination } from "src/components";
import { intl } from "src/locale";
export interface TableLayoutProps {
pagination: TablePagination;
getTableProps: any;
getTableBodyProps: any;
headerGroups: any;
rows: any;
prepareRow: any;
gotoPage: any;
canPreviousPage: any;
previousPage: any;
canNextPage: any;
nextPage: any;
pageCount: any;
pageOptions: any;
visibleColumns: any;
setAllFilters: any;
state: any;
}
function TableLayout({
pagination,
getTableProps,
getTableBodyProps,
headerGroups,
rows,
prepareRow,
gotoPage,
canPreviousPage,
previousPage,
canNextPage,
nextPage,
pageCount,
pageOptions,
visibleColumns,
setAllFilters,
state,
}: TableLayoutProps) {
const currentPage = state.pageIndex + 1;
const getPageList = () => {
const list = [];
for (let x = 0; x < pageOptions.length; x++) {
list.push(
,
);
}
return list;
};
const renderEmpty = (): ReactNode => {
return (
|
{state?.filters?.length
? intl.formatMessage(
{ id: "tables.no-items-with-filters" },
{ count: state.filters.length },
)
: intl.formatMessage({ id: "tables.no-items" })}
|
);
};
return (
<>
{headerGroups.map((headerGroup: any, idx: any) => (
{headerGroup.headers.map((column: any, idx2: any) => (
|
{column.render("Header")}
{column.sortable && column.isSorted ? (
column.isSortedDesc ? (
) : (
)
) : null}
{column.Filter ? column.render("Filter") : null}
|
))}
))}
{rows.length
? rows.map((row: any, idx: any) => {
prepareRow(row);
return (
{row.cells.map((cell: any, idx2: any) => (
|
{cell.render("Cell")}
|
))}
);
})
: renderEmpty()}
{rows.length
? intl.formatMessage(
{ id: "tables.pagination-counts" },
{
start: pagination.offset + 1,
end: Math.min(
pagination.total,
pagination.offset + pagination.limit,
),
total: pagination.total,
},
)
: null}
{state?.filters?.length ? (
setAllFilters([])}>
{intl.formatMessage(
{ id: "tables.clear-all-filters" },
{ count: state.filters.length },
)}
) : null}
>
);
}
export { TableLayout };