import { prisma } from "@/lib/db";
import { notFound } from "next/navigation";
import Link from "next/link";
import ContactDetail from "@/components/ContactDetail";

export const dynamic = "force-dynamic";

export default async function ContactDetailPage({ params }: { params: { id: string } }) {
  const id = Number(params.id);
  const contact = await prisma.contact.findUnique({
    where: { id },
    include: {
      messages: {
        orderBy: { sentAt: "asc" },
        include: { attachments: true },
      },
    },
  });

  if (!contact) notFound();

  return (
    <div>
      <Link href="/contacts" className="text-sm text-slate hover:underline">
        ← Back to contacts
      </Link>
      <ContactDetail contact={JSON.parse(JSON.stringify(contact))} />
    </div>
  );
}
