"use client"; import type { ReactNode } from "react"; import { cn } from "@/lib/utils"; import { Button, EmptyState, Spinner } from "./ui"; export interface Column { key: string; header: string; render?: (row: T) => ReactNode; className?: string; } export function DataTable({ columns, rows, loading, error, emptyTitle = "موردی ثبت نشده است", emptyMessage = "هنوز داده‌ای برای نمایش وجود ندارد.", emptyIcon, emptyAction, onRetry, actions, }: { columns: Column[]; rows: T[]; loading?: boolean; error?: string | null; emptyTitle?: string; emptyMessage?: string; emptyIcon?: ReactNode; emptyAction?: ReactNode; onRetry?: () => void; actions?: (row: T) => ReactNode; }) { if (loading) { return (
); } if (error) { return ( تلاش دوباره ) : undefined } /> ); } if (!rows.length) return ( ); return (
{columns.map((c) => ( ))} {actions && } {rows.map((row, i) => ( {columns.map((c) => ( ))} {actions && ( )} ))}
{c.header} عملیات
{c.render ? c.render(row) : ((row as Record)[c.key] as ReactNode) ?? "—"}
{actions(row)}
); }