import { Metadata } from "next";
import { Tag } from "lucide-react";
import ProductGrid from "@/components/products/ProductGrid";
import { prisma } from "@/lib/prisma";
import { serialize } from "@/lib/serialize";

export const metadata: Metadata = { title: "Deals & Offers" };

export default async function DealsPage() {
  const rawProducts = await prisma.product.findMany({
    where: { status: "ACTIVE", comparePrice: { not: null } },
    include: { brand: true, category: true, reviews: { select: { rating: true } } },
    orderBy: { createdAt: "desc" },
  });
  const products = serialize(rawProducts) as unknown as Parameters<typeof ProductGrid>[0]["products"];

  return (
    <div className="max-w-7xl mx-auto px-4 py-8">
      <div className="bg-gradient-to-r from-red-600 to-orange-500 rounded-3xl p-8 mb-8 text-white text-center">
        <Tag className="w-10 h-10 mx-auto mb-3" />
        <h1 className="text-3xl font-black mb-2">Hot Deals & Special Offers</h1>
        <p className="text-red-100">Save big on selected laptops and iPhones — limited time offers!</p>
      </div>
      <ProductGrid products={products} cols={4} />
    </div>
  );
}
