// Types import {ColumnProps} from '@src/types/common'; // Styled import { StyledBody, StyledFooter, StyledHeader, StyledRow, StyledTable, } from './styled'; // Components import Pagination from '../Pagination'; import {TbArrowNarrowRight} from 'react-icons/tb'; import {StyledTableOption} from '@src/pages/Room/styled.ts'; import OrderBy from '@src/components/OrderBy'; import {ORDERBY_OPTIONS} from '@src/constants/commons.ts'; import SortBy from '@src/components/SortBy'; import Search from '@src/components/Search'; import Direction from '@src/commons/styles/Direction.ts'; import {Dispatch, SetStateAction} from 'react'; const parseWidthString = (columnsWidth: number[]): string => { let result: string = ''; const totalWidth = columnsWidth.reduce(( partialSum, a ) => partialSum + a, 0); columnsWidth.forEach((width) => { result += Math.round(( width / totalWidth ) * 100) .toString() + '% '; }); return result; }; type Props = { columns: ColumnProps[]; rows: T[]; stateSelected: { itemSelected: T | undefined; setItemSelected: Dispatch>; }; count?: number | null; onRowClick?: (rowData: T) => void; enabledOrder?: boolean; sortBy?: { value: string; label: string; }[]; searchPlaceHolder?: string; }; const Table = ({ rows, columns, count, onRowClick, stateSelected, sortBy, searchPlaceHolder, enabledOrder = false, }: Props) => { const width = parseWidthString(columns.map((item) => item.width)); const {itemSelected, setItemSelected} = stateSelected; const headers = columns.map(( column, index ) => { return
{column.title}
; }); const renderRows = rows.map(( row, rowIndex ) => { const handleRowClick = () => { if (onRowClick) { onRowClick(row); setItemSelected(row); } }; return ( {columns.map(( column, columnIndex ) => { const value = row[column.key as keyof typeof row] as string; if (column.isDateValue) { return (
{value[0]}     {value[1]}
); } return
{value}
; })}
); }); return ( {enabledOrder && } {Boolean(sortBy?.length) && } {Boolean(searchPlaceHolder) && } {rows && rows.length && ( {headers} {renderRows} {Boolean(count) && ( )} ) } ); } export default Table;