"use client"; import { ColumnDef, flexRender, getCoreRowModel, useReactTable, getPaginationRowModel, getSortedRowModel, getFilteredRowModel } from "@tanstack/react-table"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Button } from "@app/components/ui/button"; import { useMemo, useState } from "react"; import { ExternalLink, Plus, RefreshCw } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "@app/components/ui/card"; import { Tabs, TabsList, TabsTrigger } from "@app/components/ui/tabs"; import { useTranslations } from "next-intl"; import { Badge } from "./ui/badge"; import Link from "next/link"; type TabFilter = { id: string; label: string; filterFn: (row: any) => boolean; }; type DNSRecordsDataTableProps = { columns: ColumnDef[]; data: TData[]; title?: string; addButtonText?: string; onAdd?: () => void; onRefresh?: () => void; isRefreshing?: boolean; searchPlaceholder?: string; searchColumn?: string; defaultSort?: { id: string; desc: boolean; }; tabs?: TabFilter[]; defaultTab?: string; persistPageSize?: boolean | string; defaultPageSize?: number; type?: string | null; }; export function DNSRecordsDataTable({ columns, data, title, addButtonText, onAdd, onRefresh, isRefreshing, defaultSort, tabs, defaultTab, type }: DNSRecordsDataTableProps) { const t = useTranslations(); const [activeTab, setActiveTab] = useState( defaultTab || tabs?.[0]?.id || "" ); // Apply tab filter to data const filteredData = useMemo(() => { if (!tabs || activeTab === "") { return data; } const activeTabFilter = tabs.find((tab) => tab.id === activeTab); if (!activeTabFilter) { return data; } return data.filter(activeTabFilter.filterFn); }, [data, tabs, activeTab]); const table = useReactTable({ data: filteredData, columns, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), getSortedRowModel: getSortedRowModel(), getFilteredRowModel: getFilteredRowModel() }); return (

{t("dnsRecord")}

{t("required")}
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => ( {header.isPlaceholder ? null : flexRender( header.column.columnDef .header, header.getContext() )} ))} ))} {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender( cell.column.columnDef.cell, cell.getContext() )} ))} )) ) : ( {t("noResults")} )}
); }