import { prisma } from '@/lib/prisma';
import AdminNav from '@/components/AdminNav';
import ManualSaleForm from '@/components/ManualSaleForm';

export default async function NewManualSalePage() {
  const rows = await prisma.product.findMany({ orderBy: { name: 'asc' } });
  const products = rows.map((p) => ({
    id: p.id,
    name: p.name,
    basePrice: p.basePrice,
    colors: JSON.parse(p.colors) as string[],
    sizes: p.sizes ? (JSON.parse(p.sizes) as string[]) : [],
  }));

  return (
    <div className="mx-auto max-w-2xl px-6 py-12">
      <AdminNav />
      <h1 className="font-display text-3xl">Record a sale</h1>
      <p className="mt-2 text-sm text-muted">
        For anything sold outside the website — cash at a fair, a bank transfer arranged over
        Facebook. It lands in the same ledger as website orders. If the buyer&apos;s email matches a
        customer account, the sale is linked to them automatically.
      </p>

      <ManualSaleForm products={products} />
    </div>
  );
}
