import { OptionalApp, User } from '/lib/types.ts'; import { capitalizeWord } from '/public/ts/utils/misc.ts'; interface Data { route: string; user?: User | null; enabledApps: OptionalApp[]; } interface MenuItem { url: string; label: string; } export default function Header({ route, user, enabledApps }: Data) { const activeClass = 'bg-slate-800 text-white rounded-md px-3 py-2 text-sm font-medium'; const defaultClass = 'text-slate-300 hover:bg-slate-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium'; const mobileActiveClass = 'bg-slate-800 text-white block rounded-md px-3 py-2 text-base font-medium'; const mobileDefaultClass = 'text-slate-300 hover:bg-slate-700 hover:text-white block rounded-md px-3 py-2 text-base font-medium'; const iconWidthAndHeightInPixels = 20; const potentialMenuItems: (MenuItem | null)[] = enabledApps.map((app) => ({ url: `/${app}`, label: capitalizeWord(app), })); const menuItems = potentialMenuItems.filter(Boolean) as MenuItem[]; if (user && !route.startsWith('/file-share')) { const activeMenu = menuItems.find((menu) => route.startsWith(menu.url)); let pageLabel = activeMenu?.label || '404 - Page not found'; if (route.startsWith('/news/feeds')) { pageLabel = 'News feeds'; } if (route.startsWith('/settings')) { pageLabel = 'Settings'; } if (route.startsWith('/expenses')) { pageLabel = 'Budgets & Expenses'; } if (route.startsWith('/contacts')) { pageLabel = 'Contacts'; } if (route.startsWith('/calendar')) { pageLabel = 'Calendar'; } return ( <> {menuItems.map((menu) => ( ))} {user.email} {menuItems.map((menu) => ( {menu.label} ))} {pageLabel} > ); } return ( ); }