"use client"; /** * ProfileHeader — Instagram-style centered header used at the top of * /u/me and /u/[handle]. Avatar, display name, @handle, a single stat * line, and an action row. * * The action row hosts: * • "Edit profile" link — only on the owner's own profile (via the * `editHref` prop set by /u/me layout). * • Reading-settings gear — for every signed-in viewer. It links to * /u/me/settings (a focused page that mounts ReadingSettings in * inline mode) rather than opening a popover here. A popover * triggered from this centred row tends to spill off the left edge * on narrow viewports, so the page-navigation pattern matches Edit * Profile and dodges the problem entirely. * * Anonymous visitors don't see this row at all — they read SiteHeader's * popover gear instead. */ import Image from "next/image"; import Link from "next/link"; import { Settings } from "lucide-react"; import { cn } from "@/lib/utils"; import { useAuth } from "@/components/auth/auth-provider"; export function ProfileHeader({ avatarURL, name, handle, postCount, joinedAt, editHref, }: { avatarURL: string | null; name: string; handle: string; postCount?: number; joinedAt?: string; /** When provided, shows an "Edit profile" CTA below the handle. */ editHref?: string; }) { const { user, loading } = useAuth(); // ReadingSettings appears for every authenticated viewer (own profile // OR someone else's), so an auth user reading a friend's profile can // still reach theme/palette/font controls. Anonymous viewers fall back // to SiteHeader's mobile gear. const showReadingSettings = !loading && !!user; const showActions = !!editHref || showReadingSettings; return (

{name}

@{handle}

{typeof postCount === "number" || joinedAt ? (

{typeof postCount === "number" ? ( <> {postCount} post {postCount === 1 ? "" : "s"} ) : null} {typeof postCount === "number" && joinedAt ? " · " : null} {joinedAt ? <>Joined {new Date(joinedAt).toLocaleDateString()} : null}

) : null}
{showActions ? (
{editHref ? ( Edit profile ) : null} {showReadingSettings ? ( ) : null}
) : null}
); } function Avatar({ src, name }: { src: string | null; name: string }) { if (src) { return ( {name} ); } const initials = name .split(/\s+/) .map((p) => p[0]) .slice(0, 2) .join("") .toUpperCase() || "?"; return (
{initials}
); }