'use client'
import Image from 'next/image'
import Link from 'next/link'
import { useId, useState, type ReactNode } from 'react'
import { Check, ChevronDown, Settings, Settings2 } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { useMenuPopover } from '@/shared/ui/useMenuPopover'
import Tooltip from '@/shared/ui/Tooltip'
import { useWorkspaceChoices } from '@/components/workspaces/useWorkspaceChoices'
import { VersionBadge } from '@/components/sidebar/VersionBadge'
import { clientEditionLabel } from '@/lib/version'
const GLYPH_TINTS = ['#e3655b', '#d9822b', '#c9a227', '#4f9d69', '#3d8fb8', '#6c6fd1', '#a35fc0', '#c25b8a']
/** A stable letter tile for a workspace; the general one wears the logo. */
export function WorkspaceGlyph({ name, general, size = 22 }: { name: string; general: boolean; size?: number }) {
if (general)
return (
)
let hash = 0
for (const char of name) hash = (hash * 31 + char.codePointAt(0)!) | 0
return (
{[...name.trim()][0]?.toUpperCase() ?? 'ยท'}
)
}
/** The workspaces as menu items, the current one checked. */
export function WorkspaceChoiceList({ onChoose }: { onChoose?: () => void }) {
const { t } = useTranslation()
const { active, choices, choose } = useWorkspaceChoices()
return (
<>
{t('Workspace')}
{choices.map(row => (
))}
{t('Manage workspaces')}
>
)
}
/**
* The sidebar's header: which workspace this is, and the account-level
* places (workspaces, settings, profile) that used to sit in the footer.
*/
export function WorkspaceMenu({
accountSlot,
onNavigate,
compact = false,
}: {
accountSlot?: ReactNode
onNavigate?: () => void
/** The collapsed rail's form: the workspace's mark alone, opening beside the rail. */
compact?: boolean
}) {
const { t } = useTranslation()
const { active, currentName } = useWorkspaceChoices()
const [open, setOpen] = useState(false)
const rootRef = useMenuPopover(open, setOpen)
const menuId = useId()
const close = () => {
setOpen(false)
onNavigate?.()
}
return (
{compact ? (
) : (
)}
{open && (
)}
)
}