"use client"; import { useState } from "react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { useUnconfiguredNodes } from "@/lib/useNodes"; import { useUnacknowledgedAlerts } from "@/lib/useAlerts"; import { useAuth } from "@/components/AuthProvider"; import { useTheme } from "@/components/ThemeProvider"; import { FOUNDING_ORG_ID } from "@/lib/tenancy"; // The five destinations, per UI_REDESIGN.md §3. Everything else (Settings, // Admin, Trips, Profile) lives behind the avatar — it's operator plumbing, // not a peer of Incidents. const productLinks = [ { href: "/", label: "Live" }, { href: "/incidents", label: "Incidents" }, { href: "/calls", label: "Archive" }, { href: "/watch", label: "Watch" }, ]; // Network (nodes/systems/enrollment/bot tokens — "my equipment") stays // scoped to operators and admins, matching the write-access boundary the // pages behind it have always had. const networkLink = { href: "/network", label: "Network" }; function SunIcon() { return ( ); } function MoonIcon() { return ( ); } export function Nav() { const { user, isAdmin, isOperator, isOrgOwner, orgId, signOut, refreshClaims } = useAuth(); const pathname = usePathname(); const router = useRouter(); const { nodes: pending } = useUnconfiguredNodes(); const unackedAlerts = useUnacknowledgedAlerts(); const { theme, toggle } = useTheme(); const [mobileOpen, setMobileOpen] = useState(false); const [profileMenuOpen, setProfileMenuOpen] = useState(false); const [refreshing, setRefreshing] = useState(false); if (!user) return null; async function handleSignOut() { setProfileMenuOpen(false); await signOut(); router.push("/login"); } // Re-fetches the ID token so a claims change made server-side (e.g. an // admin granting a role, or org_id being provisioned) takes effect without // a full sign-out/sign-in. See AuthProvider.refreshClaims. async function handleRefreshClaims() { setRefreshing(true); try { await refreshClaims(); } finally { setRefreshing(false); setProfileMenuOpen(false); } } const navLinks = [...productLinks, ...(isAdmin || isOperator ? [networkLink] : [])]; const showTrips = orgId === FOUNDING_ORG_ID || isAdmin; const showSettings = isAdmin || isOrgOwner; function isActive(href: string) { if (href === "/") return pathname === "/"; return pathname.startsWith(href); } function navLinkClass(href: string) { return `text-sm font-medium transition-colors shrink-0 ${ isActive(href) ? "text-ink" : "text-ink-muted hover:text-ink-2" }`; } return ( ); }