import type { Metadata } from "next";
import { currentUser } from "@/lib/session";
import { prisma } from "@/lib/db";
import { CheckoutForm } from "@/components/checkout/CheckoutForm";

export const metadata: Metadata = { title: "Checkout" };

export default async function CheckoutPage() {
  const user = await currentUser();
  let defaults = { name: "", email: "", phone: "" };
  if (user) {
    const record = await prisma.user.findUnique({ where: { id: user.id } });
    defaults = {
      name: record?.name ?? user.name,
      email: record?.email ?? user.email,
      phone: record?.phone ?? "",
    };
  }

  return (
    <div className="mx-auto max-w-5xl px-4 py-8">
      <h1 className="mb-6 text-2xl font-bold text-slate-900">Checkout</h1>
      <CheckoutForm defaults={defaults} />
    </div>
  );
}
