"use client" import { useEffect, useRef } from "react" import Link from "next/link" import { usePathname } from "next/navigation" import { useAuth } from "@/lib/auth" import { useBrand } from "@/components/brand-provider" import { DASHBOARD_NAVIGATION, currentHref } from "@/lib/dashboard-navigation" import { cn } from "@/lib/utils" // The ONE console navigation surface, in lux.cloud's shape. // // Desktop: a 236px sticky rail under the header, sections grouped under 11px // uppercase labels, rows at 8px radius that fill with `accent` when active. // // Below `lg` the rail becomes a single horizontally-scrolling strip of the // same rows. lux.cloud's note on why: wrapping the sections instead produced a // five-row wall of pills eating a quarter of a phone screen above the fold on // every page. The strip scrolls inside itself — the page body never scrolls // sideways — and the active row is scrolled into view so you can always see // where you are. export function ConsoleSidebar() { const pathname = usePathname() const { isAdmin } = useAuth() const brand = useBrand() const ref = useRef(null) const groups = DASHBOARD_NAVIGATION.map((group) => ({ ...group, items: group.items.filter((item) => !item.admin || isAdmin), })).filter((group) => group.items.length > 0) const active = currentHref( pathname, groups.flatMap((g) => g.items.map((i) => i.href)) ) useEffect(() => { ref.current?.querySelector('[data-active="true"]')?.scrollIntoView({ block: "nearest", inline: "nearest" }) }, [pathname]) const rowClass = (active: boolean) => cn( "flex shrink-0 items-center justify-between gap-2 whitespace-nowrap rounded-md px-3 py-2 text-sm transition-colors max-lg:min-h-10 max-lg:scroll-mx-3", active ? "bg-accent font-medium text-accent-foreground" : "text-muted-foreground hover:bg-foreground/5 hover:text-foreground" ) return ( ) }