import { Link, useLocation } from 'react-router-dom'
import Brand from '@/components/brand/Brand'
import LanguageSwitcher from '@/components/brand/LanguageSwitcher'
import Icon from '@/components/ui/Icon'
import SidebarNav, { NAV_ITEMS } from './SidebarNav'
import SignOutButton from './SignOutButton'
import UserBadge, { AvatarCircle } from './UserBadge'
import { useAuthStore } from '@/state/authStore'
import { useT } from '@/i18n/useT'
/**
* Where the sidebar shows and the top bar swaps its menu button for the page title.
* Tailwind needs literal class strings: two static sets, never a built string.
*/
export interface ShellBreakpoint {
sidebar: string
menuControl: string
title: string
/** The width from which the drawer has no reason to stay open. */
closesFrom: '64rem' | '80rem'
}
/** Every page but the editor: the sidebar from 1 024 px (Tailwind `lg`). */
export const DEFAULT_SHELL: ShellBreakpoint = {
sidebar: 'hidden lg:flex lg:w-64 lg:shrink-0 lg:flex-col',
menuControl: 'lg:hidden',
title: 'hidden lg:block',
closesFrom: '64rem',
}
/** The draft editor needs the width for its three columns: sidebar from 1 280 px (`xl`). */
export const EDITOR_SHELL: ShellBreakpoint = {
sidebar: 'hidden xl:flex xl:w-64 xl:shrink-0 xl:flex-col',
menuControl: 'xl:hidden',
title: 'hidden xl:block',
closesFrom: '80rem',
}
/** Title of the current /app page for the top bar, from the nav table. */
function pageTitleKey(pathname: string): string {
const match = NAV_ITEMS.find((item) =>
item.end ? item.to === pathname : pathname.startsWith(item.to) && item.to !== '/',
)
return match?.labelKey ?? 'shell.nav.dashboard'
}
export function Sidebar({ shell }: { shell: ShellBreakpoint }) {
const t = useT()
return (
)
}
interface TopBarProps {
shell: ShellBreakpoint
menuOpen: boolean
onOpenMenu: () => void
}
export function TopBar({ shell, menuOpen, onOpenMenu }: TopBarProps) {
const t = useT()
const { pathname } = useLocation()
const profile = useAuthStore((s) => s.profile)
const user = useAuthStore((s) => s.user)
const displayName = profile?.display_name ?? user?.email ?? ''
return (