"use client"; /** * DiscipleBadge — the small circular Śrīla Prabhupāda portrait that marks a * profile as belonging to one of his own initiated disciples. * * Positioned by the caller (the profile header overlaps it on the avatar's * lower-right, like a verification tick). Tapping it toggles a tooltip reading * "Śrīla Prabhupāda's Direct Disciple" — click rather than hover, so it works * identically on touch, where there is no hover state. * * The tooltip closes on a second tap, on Escape, or on any outside click. */ import { useEffect, useRef, useState } from "react"; import Image from "next/image"; import { cn } from "@/lib/utils"; const LABEL = "Śrīla Prabhupāda's Direct Disciple"; export function DiscipleBadge({ className }: { className?: string }) { const [open, setOpen] = useState(false); const wrapRef = useRef(null); // Dismiss on outside click / Escape. Bound only while open so we don't keep // document-level listeners around for every profile view. useEffect(() => { if (!open) return; function onPointerDown(e: PointerEvent) { if (!wrapRef.current?.contains(e.target as Node)) setOpen(false); } function onKey(e: KeyboardEvent) { if (e.key === "Escape") setOpen(false); } document.addEventListener("pointerdown", onPointerDown); document.addEventListener("keydown", onKey); return () => { document.removeEventListener("pointerdown", onPointerDown); document.removeEventListener("keydown", onKey); }; }, [open]); return ( {open ? ( {/* Caret pointing back at the badge. */} {LABEL} ) : null} ); }