import type { Metadata } from 'next';
import PublicProfile from './PublicProfile';

/**
 * /u/[handle] (A1 Session 10) — a user's PUBLIC ledger profile. Thin server
 * wrapper for metadata (+ the segment's opengraph-image.tsx share card);
 * the record itself renders in the PublicProfile client component.
 *
 * PUBLIC route — never gated. Publishing is the owner's explicit choice;
 * once published, the whole settled record is the page. Misses included.
 */
export async function generateMetadata({ params }: { params: Promise<{ handle: string }> }): Promise<Metadata> {
  const { handle } = await params;
  const h = decodeURIComponent(handle || '').slice(0, 20).toLowerCase();
  // Session 65 — UN-CLAIM. The title/description previously asserted a
  // closing-line-verified record while ZERO closing-line value
  // renders on this surface (beat_close_pct is null until C4 is fixed and
  // CLV_CAPTURE_RELIABLE flips; the earned directional badge is Analyst+Desk
  // and never reaches this public page). Copy now describes exactly what the
  // page shows. The claim returns, earned, when CLV genuinely renders here.
  // NOTE: layout.tsx's metadata template appends " · VYNDR" — do not repeat it.
  const title = `Settled record — @${h}`;
  const description = `@${h}'s settled betting record on VYNDR — every graded read, every result, wins and misses. Nothing curated, nothing deleted.`;
  // openGraph/twitter titles bypass the layout template, so they carry the
  // brand suffix explicitly; the page <title> must not (it would double it).
  const socialTitle = `${title} · VYNDR`;
  return {
    title,
    description,
    openGraph: { title: socialTitle, description },
    twitter: { card: 'summary_large_image', title: socialTitle, description },
  };
}

export default async function PublicProfilePage({ params }: { params: Promise<{ handle: string }> }) {
  const { handle } = await params;
  return <PublicProfile handle={decodeURIComponent(handle || '')} />;
}
