'use client' import type { ReactNode } from 'react' import { Table } from '@heroui/react' import type { PaginationListColumnType } from '@/types' import type { Selection, SortDescriptor } from '@/types/heroui' import PaginatedListColumnFilter from '@/components/paginated-list/PaginatedListColumnFilter' import PaginatedListCards from '@/components/paginated-list/PaginatedListCards' import { getActiveSortColumn, type PaginatedListFilters, type PaginatedListRow } from '@/components/paginated-list/paginatedListUtils' import Button from '@/components/formElements/Button' import ArrowSwapIcon from '@/components/icons/ArrowSwapIcon' import { TableSkeleton } from '@/components/feedback/LoadingState' import AdminState from '@/components/feedback/AdminState' interface Props { bottomContent: ReactNode columns: PaginationListColumnType[] data: PaginatedListRow[] filters: PaginatedListFilters isLoading: boolean loadError: string | null selectedKeys: Selection selectionMode: 'single' | 'multiple' | 'none' sortDescriptor: SortDescriptor sortString: string tableWrapperClass: string topContent: ReactNode onRemoveFilter: (field: string, nestedField?: 'from' | 'to') => void onRetry: () => void onRenderCell: (item: PaginatedListRow, columnKey: React.Key) => ReactNode onRunFilters: () => void onSelectedKeysChange: (keys: Selection) => void onSetFilter: (field: string, value: string | number, nestedField?: 'from' | 'to') => void onSetSelectFilter: (field: string, value: string) => void onSortChange: React.Dispatch> } export default function PaginatedListTable({ bottomContent, columns, data, filters, isLoading, loadError, selectedKeys, selectionMode, sortDescriptor, sortString, tableWrapperClass, topContent, onRemoveFilter, onRetry, onRenderCell, onRunFilters, onSelectedKeysChange, onSetFilter, onSetSelectFilter, onSortChange, }: Props) { const isInitialLoading = isLoading && data.length === 0 const isRefreshing = isLoading && data.length > 0 // In RTL, the last column sits on the visual left — keep actions there. const orderedColumns = [ ...columns.filter((column) => column.field !== 'actions'), ...columns.filter((column) => column.field === 'actions'), ] const rowHeaderField = orderedColumns.find((column) => column.field !== 'actions')?.field ?? orderedColumns[0]?.field return (
{isRefreshing ? (
در حال به‌روزرسانی جدول
) : null} {topContent} {loadError ? ( ) : null} {selectionMode === 'none' ? ( ) : null}
{ onSelectedKeysChange(keys === 'all' ? 'all' : new Set(Array.from(keys, String))) }} > {(column) => { const isActions = column.field === 'actions' return ( { const target = event.target as HTMLElement if (target.tagName === 'INPUT') target.focus() }} >

{column.label}

{column.sortable && ( )}
) }}
isInitialLoading ? (
) : ( ) } > {(item) => ( {(column) => { const key = column.field return ( {onRenderCell(item, key)} ) }} )}
{bottomContent}
) }