"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useEffect, useRef, useState } from "react"; import { logout } from "@/app/auth-actions"; type Props = { username: string }; export default function Nav({ username }: Props) { const pathname = usePathname() ?? "/"; const isPasskeys = pathname.startsWith("/cm-passkeys"); const isUsers = pathname.startsWith("/users"); const isAccounts = !isUsers && !isPasskeys; const initial = (username[0] ?? "?").toUpperCase(); return ( CM CM Bot V2 Account dashboard Accounts Users ); } function NavLink({ href, active, children, }: { href: string; active: boolean; children: React.ReactNode; }) { return ( {children} ); } function AccountMenu({ username, initial, }: { username: string; initial: string; }) { const [open, setOpen] = useState(false); const wrapperRef = useRef(null); useEffect(() => { if (!open) return; function onPointerDown(e: PointerEvent) { if (!wrapperRef.current) return; if (!wrapperRef.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 ( setOpen((v) => !v)} aria-haspopup="menu" aria-expanded={open} className="inline-flex items-center gap-2 rounded-full px-2 py-1 text-xs font-medium text-zinc-700 transition-colors hover:bg-zinc-100" > {initial} {username} {open && ( {username} setOpen(false)} className="block px-3 py-2 text-xs text-zinc-700 transition-colors hover:bg-zinc-50 hover:text-zinc-900" > Passkey settings setOpen(false)} className="block w-full px-3 py-2 text-left text-xs text-zinc-700 transition-colors hover:bg-zinc-50 hover:text-red-600" > Sign out )} ); }