"use client"; import { useEffect, useState } from "react"; import { Building2 } from "lucide-react"; // ── Helpers ─────────────────────────────────────────────────────────────────── function getStoredOrgId(): string | null { // Guard against SSR — localStorage not available on server if (typeof window === "undefined") return null; try { return localStorage.getItem("gd_org_id"); } catch { return null; } } function orgInitials(orgId: string): string { // Build a 2-letter monogram from org ID string const parts = orgId .toUpperCase() .replace(/[^A-ZА-Я0-9]/gu, " ") .split(" ") .filter(Boolean); if (parts.length === 0) return "??"; if (parts.length === 1) return parts[0].slice(0, 2); return parts[0][0] + parts[1][0]; } // ── Component ───────────────────────────────────────────────────────────────── export function UserAvatar() { const [orgId, setOrgId] = useState(null); // Hydration-safe: read localStorage after mount useEffect(() => { setOrgId(getStoredOrgId()); }, []); const displayLabel = orgId ?? "Demo Org"; const initials = orgId ? orgInitials(orgId) : "DO"; return (
{/* Avatar circle */}
{orgId ? ( {initials} ) : ( )}
{/* Org name — hidden on narrow viewports via maxWidth trick */} {displayLabel}
); }