import { notFound } from "next/navigation";
import type { Metadata } from "next";
import PolicyLayout from "@/components/PolicyLayout";
import PageBody from "@/components/PageBody";
import { prisma } from "@/lib/prisma";
import { formatDate } from "@/lib/format";

export async function generateMetadata(): Promise<Metadata> {
  const page = await prisma.pageSeo.findUnique({ where: { path: "/privacy-policy" } });
  return { title: page?.title || "Privacy Policy — Iniyaval Return Gifts", description: page?.description || undefined };
}

export default async function PrivacyPolicyPage() {
  const page = await prisma.staticPage.findUnique({ where: { path: "/privacy-policy" } });
  if (!page) notFound();

  return (
    <PolicyLayout title={page.title} updated={formatDate(page.updatedAt)}>
      <PageBody body={page.body} />
    </PolicyLayout>
  );
}
