import ProfileView from "@/components/admin/ProfileView";
import { readSession } from "@/lib/api/admin-server";
import { toProfileView } from "@/lib/view-models";

export const dynamic = "force-dynamic";

export const metadata = { title: "Profile — RSVP Admin" };

/**
 * The signed-in admin's own account (spec admin-auth, task 9.5).
 *
 * Reachable by every admin, unlike the roster. The session is already resolved by the
 * protected layout, but it is read again here rather than threaded down — one extra
 * server-side call against the internal network, against a prop that would otherwise have to
 * cross every intervening component.
 *
 * Mapped through a view model before it reaches the client component: this page renders a
 * real person's email address into the HTML payload (design D8).
 */
export default async function ProfilePage() {
  const session = await readSession();
  // The layout has already redirected an unauthenticated visitor; this satisfies the type.
  if (!session) return null;

  return <ProfileView profile={toProfileView(session)} />;
}
