// app/(public)/participar/gracias/page.tsx
// Confirmation screen (Screen E). Server shell that reads the purchase id from
// the query string and the public share base URL from env, then hands off to
// the client <Confirmation>, which polls status as a UX hint (never truth) and
// surfaces the share + "Quiero mas chances" loop.

import * as React from "react";
import { env } from "@/lib/env";
import { Confirmation } from "@/components/flow/Confirmation";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";

function firstParam(v: string | string[] | undefined): string | undefined {
  if (Array.isArray(v)) return v[0];
  return v;
}

export default async function GraciasPage({
  searchParams,
}: {
  searchParams: Promise<Record<string, string | string[] | undefined>>;
}) {
  const params = await searchParams;
  const purchaseId = firstParam(params.purchase) ?? null;

  // The share artifact links to the public landing only. No personal data.
  const shareBaseUrl = env.NEXT_PUBLIC_APP_URL ?? "https://rifa.teleton.pe";

  return <Confirmation purchaseId={purchaseId} shareBaseUrl={shareBaseUrl} />;
}

export const metadata = {
  title: "Gracias por participar en la rifa de Teletón",
  // Confirmation pages should not be indexed (they are per-purchase landings).
  robots: { index: false, follow: false },
};
