"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Sun, Moon, ChevronDown, LogOut } from "lucide-react"; import { useAuth } from "@abe-kap/appshell-sdk/react"; import { Icon } from "./ui"; import { user } from "./account-data"; function initialsOf(name: string): string { return name.split(/\s+/).filter(Boolean).slice(0, 2).map((p) => p[0]).join("").toUpperCase() || "?"; } export function Topbar({ theme, onToggle, title, subtitle }: { theme: "dark" | "light"; onToggle: () => void; title: string; subtitle: string }) { // When signed in through the Shell, show the real identity from the App Context // Envelope; otherwise fall back to the static demo user. const router = useRouter(); const { user: me, logout, context } = useAuth(); const [menuOpen, setMenuOpen] = useState(false); const roleLabel = context?.scope?.role ? context.scope.role.charAt(0).toUpperCase() + context.scope.role.slice(1) : ""; const name = me?.displayName || user.name; const initials = me ? initialsOf(me.displayName) : user.initials; const secondary = me?.email || roleLabel || user.role; async function signOut() { setMenuOpen(false); try { await logout(); } catch { /* ignore */ } router.replace("/portal/login"); } return (

{title}

{subtitle}

{menuOpen && ( <>
setMenuOpen(false)} />
)}
); }