import { Button } from '@/vdb/components/ui/button.js'; import { useDynamicTranslations } from '@/vdb/hooks/use-dynamic-translations.js'; import { ColumnDef, HeaderContext } from '@tanstack/table-core'; import { ArrowDown, ArrowUp, ArrowUpDown } from 'lucide-react'; import { useMemo } from 'react'; import { ColumnHeaderWrapper } from './column-header-wrapper.js'; export interface DataTableColumnHeaderProps { customConfig: Partial>; headerContext: HeaderContext; } export function DataTableColumnHeader({ headerContext, customConfig }: Readonly) { const { column } = headerContext; const isSortable = column.getCanSort(); const { getTranslatedFieldName } = useDynamicTranslations(); const display = useMemo(() => { const customHeader = customConfig.header; let result = getTranslatedFieldName(column.id); if (typeof customHeader === 'function') { result = customHeader(headerContext); } else if (typeof customHeader === 'string') { result = customHeader; } return result; }, [customConfig.header, column.id, getTranslatedFieldName]); const columSort = column.getIsSorted(); const nextSort = columSort === 'asc' ? true : columSort === 'desc' ? undefined : false; return (
{isSortable && ( )}
{display}
); }