"use client" import { Plus, Edit2, Trash2 } from "lucide-react" import { Button } from "@/components/ui/button" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip" import { Skeleton } from "@/components/ui/skeleton" interface Column { key: string header: string render?: (item: T) => React.ReactNode } interface DataTableProps { title: string data: T[] columns: Column[] onAddNew: () => void addButtonText: string isLoading?: boolean onEdit?: (item: T) => void onDelete?: (item: T) => void } export function DataTable>({ title, data, columns, onAddNew, addButtonText, isLoading = false, onEdit, onDelete }: DataTableProps) { const showActions = !!onEdit || !!onDelete; const totalCols = columns.length + (showActions ? 1 : 0); return (
{/* Header with Title and Add Button */}

{title}

{data.length}
{/* Table */}
{columns.map((col) => ( ))} {showActions && ( )} {isLoading ? ( Array.from({ length: 5 }).map((_, idx) => ( {columns.map((col) => ( ))} {showActions && ( )} )) ) : data.length === 0 ? ( ) : ( data.map((item, idx) => ( {columns.map((col) => ( ))} {showActions && ( )} )) )}
{col.header} Actions

No data available

Click "{addButtonText}" to get started

{col.render ? col.render(item) : (item[col.key as keyof T] !== null && item[col.key as keyof T] !== undefined ? String(item[col.key as keyof T]) : "—")}
{onEdit && (

Edit

)} {onDelete && (

Delete

)}
) }