import { columns } from "@/app/my/jobs/columns";
import { JobsTable } from "@/app/my/jobs/data-table";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { db } from "@/server/db";
import { printJobs } from "@/server/db/schema";
import { desc } from "drizzle-orm";
import type { Metadata } from "next";

export const metadata: Metadata = {
	title: "Alle Druckaufträge",
};

export default async function AdminJobsPage() {
	const allJobs = await db.query.printJobs.findMany({
		orderBy: [desc(printJobs.startAt)],
		with: {
			user: true,
			printer: true,
		},
	});

	return (
		<Card>
			<CardHeader className="flex flex-row justify-between items-center">
				<div>
					<CardTitle>Druckaufträge</CardTitle>
					<CardDescription>Alle Druckaufträge</CardDescription>
				</div>
			</CardHeader>
			<CardContent>
				<JobsTable columns={columns} data={allJobs} />
			</CardContent>
		</Card>
	);
}
