import { useEffect, useId, useRef, useState } from 'react'; import { SHELL_HEADER_MIN_CLASS } from '../constants/shellChrome'; import type { SikshyaShellUser } from '../types'; import { __ } from '../lib/i18n'; import { NavIcon } from './NavIcon'; import { GlobalSearchPalette } from './GlobalSearchPalette'; type Props = { title: string; /** Accepted for API compatibility; not shown in the top chrome (page titles only). */ subtitle?: string; badge?: string; user?: SikshyaShellUser; adminUrl: string; toolsHref?: string; isDark: boolean; onToggleDark: () => void; }; const menuLinkClass = 'flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left text-sm font-medium text-slate-700 transition-colors hover:bg-slate-100 dark:text-slate-200 dark:hover:bg-slate-800'; const COMMUNITY_GROUP_URL = 'https://www.facebook.com/groups/sikshyalms/'; /** * Top chrome always uses default light/dark shell styling. White-label colours apply to * the sidebar and to the global `brand-*` accent (see {@link applyAdminBrandThemeToRoot}), not here. */ export function TopBar({ title, subtitle: _subtitle, badge, user, adminUrl, toolsHref, isDark, onToggleDark, }: Props) { const wpIndex = `${adminUrl.replace(/\/?$/, '/')}index.php`; const [menuOpen, setMenuOpen] = useState(false); const wrapRef = useRef(null); const menuId = useId(); const safeUser: SikshyaShellUser = user || { name: __('Admin', 'sikshya'), avatarUrl: '' }; const { name, avatarUrl, email, profileUrl, logoutUrl } = safeUser; const initial = name.trim().charAt(0).toUpperCase() || '?'; useEffect(() => { if (!menuOpen) { return; } const onDocMouseDown = (e: MouseEvent) => { const el = wrapRef.current; if (!el || el.contains(e.target as Node)) { return; } setMenuOpen(false); }; const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') { setMenuOpen(false); } }; document.addEventListener('mousedown', onDocMouseDown); document.addEventListener('keydown', onKey); return () => { document.removeEventListener('mousedown', onDocMouseDown); document.removeEventListener('keydown', onKey); }; }, [menuOpen]); return (

{title}

{badge ? (

{badge}

) : null}
{__('Back to WordPress', 'sikshya')} {__('Join Community', 'sikshya')} {toolsHref ? ( {__('Tools', 'sikshya')} ) : null}
{menuOpen ? ( ) : null}
); }