import { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import prisma from "@/lib/db"; import Link from "next/link"; import { auth } from "@/lib/auth"; import { cn } from "@/lib/utils"; import type { Prisma } from "@prisma/client"; import { Calendar } from "lucide-react"; import { headers } from "next/headers"; import Pagination from "./pagination"; import { Badge } from "./ui/badge"; import { Button } from "./ui/button"; import { Separator } from "./ui/separator"; type PaymentWithDevices = Prisma.PaymentGetPayload<{ include: { devices: true; }; }> export async function PaymentsTable({ searchParams, }: { searchParams: Promise<{ query: string; page: number; sortBy: string; }>; }) { const session = await auth.api.getSession({ headers: await headers() }) const query = (await searchParams)?.query || ""; const page = (await searchParams)?.page; const totalPayments = await prisma.payment.count({ where: { userId: session?.session.userId, OR: [ { devices: { every: { name: { contains: query || "", mode: "insensitive", }, }, }, }, ], }, }); const totalPages = Math.ceil(totalPayments / 10); const limit = 10; const offset = (Number(page) - 1) * limit || 0; const payments = await prisma.payment.findMany({ where: { userId: session?.session.userId, OR: [ { devices: { every: { name: { contains: query || "", mode: "insensitive", }, }, }, }, ], }, include: { devices: true }, skip: offset, take: limit, orderBy: { createdAt: "desc", }, }); return (