"use client"; import React, { useState, useMemo } from "react"; import { ChevronLeft, ChevronRight, ArrowUpDown } from "lucide-react"; export interface TableColumn { key: string; header: string; render?: (row: T) => React.ReactNode; sortable?: boolean; } interface GlassTableProps { columns: TableColumn[]; data: T[]; pageSize?: number; emptyMessage?: string; onRowClick?: (row: T) => void; } function sortByColumn>(a: T, b: T, key: string, asc: boolean): number { const aVal = a[key]; const bVal = b[key]; if (aVal === bVal) return 0; if (aVal == null) return 1; if (bVal == null) return -1; const cmp = String(aVal).localeCompare(String(bVal), undefined, { numeric: true }); return asc ? cmp : -cmp; } export default function GlassTable>({ columns, data, pageSize = 10, emptyMessage = "No data found", onRowClick, }: GlassTableProps): React.ReactElement { const [page, setPage] = useState(0); const [sortKey, setSortKey] = useState(null); const [sortAsc, setSortAsc] = useState(true); const sorted = useMemo(() => { if (!sortKey) return data; return [...data].sort((a, b) => sortByColumn(a, b, sortKey, sortAsc)); }, [data, sortKey, sortAsc]); const totalPages = Math.max(1, Math.ceil(sorted.length / pageSize)); const paginated = sorted.slice(page * pageSize, (page + 1) * pageSize); function handleSort(key: string): void { if (sortKey === key) { setSortAsc(!sortAsc); } else { setSortKey(key); setSortAsc(true); } setPage(0); } if (data.length === 0) { return (

{emptyMessage}

); } return (
{columns.map((col) => ( ))} {paginated.map((row, i) => ( onRowClick(row) : undefined} className={onRowClick ? "cursor-pointer" : ""} > {columns.map((col) => ( ))} ))}
handleSort(col.key) : undefined} className={`${col.sortable ? "cursor-pointer select-none hover:text-slate-300" : ""} sticky top-0 bg-[#080916]/95 backdrop-blur-md z-10`} > {col.header} {col.sortable && }
{col.render ? col.render(row) : (row[col.key] as React.ReactNode) ?? "—"}
{totalPages > 1 && (
{page * pageSize + 1}–{Math.min((page + 1) * pageSize, sorted.length)} of {sorted.length}
{page + 1} / {totalPages}
)}
); }