import Link from 'next/link';
import { notFound } from 'next/navigation';
import { prisma } from '@/lib/prisma';

export default async function CustomRequestSubmittedPage({
  searchParams,
}: {
  searchParams: { id?: string };
}) {
  const id = searchParams.id ?? '';
  const request = id
    ? await prisma.customRequest.findUnique({ where: { id }, include: { product: true } })
    : null;
  if (!request) notFound();

  return (
    <div className="mx-auto max-w-xl px-6 py-16 text-center">
      <p className="tag-label text-splash-pink">Got it</p>
      <h1 className="mt-2 font-display text-3xl">Thanks — we've got your photo</h1>
      <p className="mt-3 text-sm text-muted">
        We'll take a look and get back to you at {request.customerEmail} with a design to review.
      </p>

      <div className="mt-8 border border-line bg-surface p-6">
        <img
          src={request.imageDataUrl}
          alt="Your submitted photo"
          className="mx-auto max-h-64 object-contain"
        />
        <p className="mt-3 text-sm text-muted">For a {request.product.name}</p>
      </div>

      <Link href="/" className="mt-8 inline-block tag-label hover:text-ink">
        ← Back to the shop
      </Link>
    </div>
  );
}
