{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar-workspace",
  "type": "registry:component",
  "title": "Sidebar Workspace",
  "description": "A workspace app sidebar with a keyboard-friendly workspace switcher, sections with counts, collapsible favorites, a usage card with an upgrade button and a user menu.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "sidebars",
    "sidebar",
    "workspace",
    "switcher",
    "usage",
    "favorites",
    "saas"
  ],
  "docs": "https://hyperblur.dev/effects/sidebar-workspace",
  "files": [
    {
      "path": "registry/hyperblur/sidebar-workspace.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/sidebar-workspace.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nconst ICONS = {\n  inbox:\n    \"M3.5 11.5h3.2l.9 1.8h4.8l.9-1.8h3.2M3.5 11.5l1.8-6.2a1 1 0 0 1 1-.7h7.4a1 1 0 0 1 1 .7l1.8 6.2v3.7a1 1 0 0 1-1 1H4.5a1 1 0 0 1-1-1z\",\n  tasks: \"M4 5.5l1.5 1.5L8 4.5M4 11.5L5.5 13 8 10.5M11 6h5M11 12h5\",\n  folder:\n    \"M3 6.2a1.5 1.5 0 0 1 1.5-1.5h3.1l1.6 1.8h5.8A1.5 1.5 0 0 1 16.5 8v6.3a1.5 1.5 0 0 1-1.5 1.5H4.5A1.5 1.5 0 0 1 3 14.3z\",\n  chart: \"M4 16V9M10 16V4M16 16v-5\",\n  users:\n    \"M7.5 9a2.7 2.7 0 1 0 0-5.4 2.7 2.7 0 0 0 0 5.4zM2.5 16.2c.4-2.7 2.5-4.2 5-4.2s4.6 1.5 5 4.2M13 4.2a2.7 2.7 0 0 1 0 5M14.5 12.2c1.6.5 2.7 1.8 3 4\",\n  calendar:\n    \"M4.5 5h11a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1zM3.5 8.5h13M7 3.5v3M13 3.5v3\",\n  search: \"M9 15a6 6 0 1 0 0-12 6 6 0 0 0 0 12zM14 14l3 3\",\n} as const;\n\nexport type SidebarWorkspaceIconName = keyof typeof ICONS;\n\nexport function SidebarWorkspaceIcon({ name }: { name: SidebarWorkspaceIconName }) {\n  return (\n    <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d={ICONS[name]} />\n    </svg>\n  );\n}\n\nexport interface SidebarWorkspaceSpace {\n  id: string;\n  name: string;\n  plan?: string;\n  color?: string;\n}\n\nexport interface SidebarWorkspaceItem {\n  id: string;\n  label: string;\n  icon?: React.ReactNode;\n  count?: number | string;\n  href?: string;\n}\n\nexport interface SidebarWorkspaceSection {\n  label?: string;\n  items: SidebarWorkspaceItem[];\n}\n\nexport interface SidebarWorkspaceFavorite {\n  id: string;\n  label: string;\n  color?: string;\n}\n\nexport interface SidebarWorkspaceUsage {\n  label: string;\n  used: number;\n  total: number;\n  caption?: string;\n}\n\nexport interface SidebarWorkspaceUser {\n  name: string;\n  email?: string;\n  color?: string;\n}\n\nexport interface SidebarWorkspaceMenuItem {\n  id: string;\n  label: string;\n  danger?: boolean;\n}\n\nexport interface SidebarWorkspaceProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, \"onChange\" | \"children\" | \"defaultValue\"> {\n  workspaces?: SidebarWorkspaceSpace[];\n  workspace?: string;\n  defaultWorkspace?: string;\n  onWorkspaceChange?: (id: string) => void;\n  onCreateWorkspace?: () => void;\n  sections?: SidebarWorkspaceSection[];\n  favorites?: SidebarWorkspaceFavorite[];\n  favoritesLabel?: string;\n  defaultFavoritesOpen?: boolean;\n  active?: string;\n  defaultActive?: string;\n  onChange?: (id: string) => void;\n  usage?: SidebarWorkspaceUsage | null;\n  upgradeLabel?: string;\n  onUpgrade?: () => void;\n  user?: SidebarWorkspaceUser | null;\n  userMenu?: SidebarWorkspaceMenuItem[];\n  onUserMenuSelect?: (id: string) => void;\n  width?: number;\n  rowHeight?: number;\n  color?: string;\n}\n\nconst defaultWorkspaces: SidebarWorkspaceSpace[] = [\n  { id: \"northwind\", name: \"Northwind\", plan: \"Team plan\", color: \"#2f7bff\" },\n  { id: \"studio\", name: \"Fable Studio\", plan: \"Pro plan\", color: \"#e5484d\" },\n  { id: \"personal\", name: \"Personal\", plan: \"Free plan\", color: \"#30a46c\" },\n];\n\nconst defaultSections: SidebarWorkspaceSection[] = [\n  {\n    items: [\n      { id: \"inbox\", label: \"Inbox\", icon: <SidebarWorkspaceIcon name=\"inbox\" />, count: 8 },\n      { id: \"tasks\", label: \"My tasks\", icon: <SidebarWorkspaceIcon name=\"tasks\" />, count: 14 },\n      { id: \"projects\", label: \"Projects\", icon: <SidebarWorkspaceIcon name=\"folder\" />, count: 6 },\n    ],\n  },\n  {\n    label: \"Insights\",\n    items: [\n      { id: \"reports\", label: \"Reports\", icon: <SidebarWorkspaceIcon name=\"chart\" /> },\n      { id: \"people\", label: \"People\", icon: <SidebarWorkspaceIcon name=\"users\" />, count: 23 },\n    ],\n  },\n];\n\nconst defaultFavorites: SidebarWorkspaceFavorite[] = [\n  { id: \"fav-roadmap\", label: \"Q4 roadmap\", color: \"#2f7bff\" },\n  { id: \"fav-launch\", label: \"Launch checklist\", color: \"#f5a623\" },\n  { id: \"fav-research\", label: \"User research\", color: \"#30a46c\" },\n];\n\nconst defaultUsage: SidebarWorkspaceUsage = { label: \"Storage\", used: 7.2, total: 10, caption: \"7.2 of 10 GB used\" };\n\nconst defaultUser: SidebarWorkspaceUser = { name: \"Daniel Okoye\", email: \"daniel@northwind.co\" };\n\nconst defaultMenu: SidebarWorkspaceMenuItem[] = [\n  { id: \"profile\", label: \"Profile\" },\n  { id: \"settings\", label: \"Settings\" },\n  { id: \"signout\", label: \"Sign out\", danger: true },\n];\n\nconst css = `\n.hb-swk {\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  gap: 4px;\n  box-sizing: border-box;\n  width: var(--hb-swk-w, 260px);\n  max-width: 100%;\n  height: 100%;\n  min-height: 0;\n  padding: 6px;\n  border-right: 1px solid #262626;\n  background: #111111;\n  color: #ededed;\n  font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif);\n  font-size: 13px;\n  line-height: 18px;\n  --hb-swk-accent: #2f7bff;\n}\n.hb-swk *, .hb-swk *::before, .hb-swk *::after { box-sizing: border-box; }\n.hb-swk-top { position: relative; flex: none; }\n.hb-swk-switch {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  width: 100%;\n  height: calc(var(--hb-swk-row, 32px) + 8px);\n  margin: 0;\n  padding: 0 6px 0 5px;\n  border: 1px solid transparent;\n  border-radius: 9px;\n  background: transparent;\n  color: inherit;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .15s ease, border-color .15s ease;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-swk-switch:hover, .hb-swk-switch[aria-expanded=\"true\"] { background: #1a1a1a; border-color: #262626; }\n.hb-swk-switch:focus-visible { outline: 2px solid var(--hb-swk-accent); outline-offset: 1px; }\n.hb-swk-mark {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: calc(var(--hb-swk-row, 32px) - 6px);\n  height: calc(var(--hb-swk-row, 32px) - 6px);\n  min-width: 18px;\n  min-height: 18px;\n  border-radius: 7px;\n  background: var(--hb-swk-c, #2f7bff);\n  color: #ffffff;\n  font-size: 11px;\n  font-weight: 700;\n  line-height: 1;\n  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2);\n}\n.hb-swk-who { display: flex; flex: 1; flex-direction: column; min-width: 0; }\n.hb-swk-wname { overflow: hidden; font-size: 12.5px; font-weight: 600; line-height: 14px; text-overflow: ellipsis; white-space: nowrap; }\n.hb-swk-wplan { overflow: hidden; color: #8f8f8f; font-size: 10.5px; line-height: 12px; text-overflow: ellipsis; white-space: nowrap; }\n.hb-swk-caret { flex: none; width: 14px; height: 14px; color: #77777f; }\n.hb-swk-pop {\n  position: absolute;\n  top: calc(100% + 4px);\n  left: 0;\n  right: 0;\n  z-index: 30;\n  padding: 4px;\n  border: 1px solid #2a2a2a;\n  border-radius: 12px;\n  background: #171717;\n  box-shadow: 0 18px 40px rgba(0, 0, 0, .55), 0 2px 8px rgba(0, 0, 0, .3);\n  transform-origin: top center;\n  animation: hb-swk-pop .16s cubic-bezier(.2, .9, .2, 1) both;\n}\n.hb-swk-pop[data-up=\"true\"] { top: auto; bottom: calc(100% + 4px); transform-origin: bottom center; }\n.hb-swk-list { margin: 0; padding: 0; list-style: none; outline: 0; }\n.hb-swk-opt {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  height: 34px;\n  padding: 0 8px 0 6px;\n  border-radius: 8px;\n  color: #d4d4d4;\n  cursor: pointer;\n}\n.hb-swk-opt[data-hi=\"true\"] { background: #232323; color: #ffffff; }\n.hb-swk-opt .hb-swk-mark { width: 22px; height: 22px; }\n.hb-swk-list:focus-visible { outline: 2px solid var(--hb-swk-accent); outline-offset: 1px; border-radius: 8px; }\n.hb-swk-check { flex: none; width: 14px; height: 14px; color: var(--hb-swk-accent); }\n.hb-swk-sep { height: 1px; margin: 4px 2px; background: #262626; }\n.hb-swk-create {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  width: 100%;\n  height: 30px;\n  margin: 0;\n  padding: 0 8px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #a1a1a1;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n}\n.hb-swk-create:hover { background: #232323; color: #ededed; }\n.hb-swk-create:focus-visible { outline: 2px solid var(--hb-swk-accent); outline-offset: -2px; }\n.hb-swk-create svg { width: 14px; height: 14px; }\n.hb-swk-mid { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #2a2a2a transparent; }\n.hb-swk-sec + .hb-swk-sec, .hb-swk-sec + .hb-swk-fav { margin-top: 8px; }\n.hb-swk-label { height: 20px; padding: 0 8px; color: #77777f; font-size: 11px; font-weight: 600; letter-spacing: .05em; line-height: 20px; text-transform: uppercase; }\n.hb-swk-items { display: flex; flex-direction: column; gap: 1px; margin: 0; padding: 0; list-style: none; }\n.hb-swk-item {\n  display: flex;\n  align-items: center;\n  gap: 9px;\n  width: 100%;\n  height: var(--hb-swk-row, 32px);\n  margin: 0;\n  padding: 0 8px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #a1a1a1;\n  font: inherit;\n  font-weight: 500;\n  text-align: left;\n  text-decoration: none;\n  cursor: pointer;\n  transition: background-color .15s ease, color .15s ease;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-swk-item:hover { background: #1a1a1a; color: #ededed; }\n.hb-swk-item[aria-current=\"page\"] { background: #202020; color: #ffffff; }\n.hb-swk-item:focus-visible { outline: 2px solid var(--hb-swk-accent); outline-offset: -2px; }\n.hb-swk-ico { display: grid; flex: none; place-items: center; width: 16px; height: 16px; }\n.hb-swk-ico svg { width: 16px; height: 16px; }\n.hb-swk-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.hb-swk-count { flex: none; color: #77777f; font-size: 12px; font-variant-numeric: tabular-nums; }\n.hb-swk-item[aria-current=\"page\"] .hb-swk-count { color: #d4d4d4; }\n.hb-swk-fhead {\n  display: flex;\n  align-items: center;\n  gap: 4px;\n  width: 100%;\n  height: 20px;\n  margin: 0;\n  padding: 0 6px 0 8px;\n  border: 0;\n  border-radius: 6px;\n  background: transparent;\n  color: #77777f;\n  font: inherit;\n  font-size: 11px;\n  font-weight: 600;\n  letter-spacing: .05em;\n  text-align: left;\n  text-transform: uppercase;\n  cursor: pointer;\n  transition: color .15s ease;\n}\n.hb-swk-fhead:hover { color: #ededed; }\n.hb-swk-fhead:focus-visible { outline: 2px solid var(--hb-swk-accent); outline-offset: -2px; }\n.hb-swk-chev { flex: none; width: 12px; height: 12px; transition: transform .28s cubic-bezier(.2, .9, .2, 1); }\n.hb-swk-fhead[aria-expanded=\"true\"] .hb-swk-chev { transform: rotate(90deg); }\n.hb-swk-fold {\n  display: grid;\n  grid-template-rows: 0fr;\n  visibility: hidden;\n  transition: grid-template-rows .3s cubic-bezier(.2, .9, .2, 1), visibility 0s linear .3s;\n}\n.hb-swk-fold[data-open=\"true\"] { grid-template-rows: 1fr; visibility: visible; transition-delay: 0s; }\n.hb-swk-fin { min-height: 0; overflow: hidden; }\n.hb-swk-fin .hb-swk-items { padding-top: 2px; }\n.hb-swk-fav-item { height: calc(var(--hb-swk-row, 32px) - 2px); }\n.hb-swk-dot { flex: none; width: 8px; height: 8px; margin: 0 4px; border-radius: 999px; background: var(--hb-swk-c, #8f8f8f); }\n.hb-swk-bottom { display: flex; flex: none; flex-direction: column; gap: 4px; }\n.hb-swk-usage { padding: 8px 10px; border: 1px solid #262626; border-radius: 10px; background: #151515; }\n.hb-swk-urow { display: flex; align-items: center; justify-content: space-between; gap: 8px; }\n.hb-swk-ulabel { overflow: hidden; font-size: 12px; font-weight: 500; line-height: 20px; text-overflow: ellipsis; white-space: nowrap; }\n.hb-swk-up {\n  flex: none;\n  height: 20px;\n  margin: 0;\n  padding: 0 9px;\n  border: 0;\n  border-radius: 999px;\n  background: #ededed;\n  color: #0a0a0a;\n  font: inherit;\n  font-size: 11px;\n  font-weight: 600;\n  cursor: pointer;\n  transition: background-color .15s ease, transform .15s ease;\n}\n.hb-swk-up:hover { background: #ffffff; }\n.hb-swk-up:active { transform: scale(.96); }\n.hb-swk-up:focus-visible { outline: 2px solid var(--hb-swk-accent); outline-offset: 2px; }\n.hb-swk-bar { position: relative; height: 4px; margin-top: 6px; overflow: hidden; border-radius: 999px; background: #262626; }\n.hb-swk-fill {\n  position: absolute;\n  inset: 0;\n  border-radius: 999px;\n  background: linear-gradient(90deg, var(--hb-swk-accent), #7fb3ff);\n  transform: scaleX(var(--hb-swk-p, 0));\n  transform-origin: left center;\n  animation: hb-swk-grow .9s cubic-bezier(.2, .9, .2, 1) both;\n}\n.hb-swk-fill[data-warn=\"true\"] { background: linear-gradient(90deg, #f5a623, #ff6b4a); }\n.hb-swk-cap { margin-top: 5px; color: #8f8f8f; font-size: 11px; line-height: 14px; }\n.hb-swk-userwrap { position: relative; }\n.hb-swk-user {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  width: 100%;\n  height: calc(var(--hb-swk-row, 32px) + 6px);\n  margin: 0;\n  padding: 0 6px 0 5px;\n  border: 0;\n  border-radius: 9px;\n  background: transparent;\n  color: inherit;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .15s ease;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-swk-user:hover, .hb-swk-user[aria-expanded=\"true\"] { background: #1a1a1a; }\n.hb-swk-user:focus-visible { outline: 2px solid var(--hb-swk-accent); outline-offset: 1px; }\n.hb-swk-avatar {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: calc(var(--hb-swk-row, 32px) - 6px);\n  height: calc(var(--hb-swk-row, 32px) - 6px);\n  min-width: 18px;\n  min-height: 18px;\n  border-radius: 999px;\n  color: #ffffff;\n  font-size: 10.5px;\n  font-weight: 700;\n  line-height: 1;\n}\n.hb-swk-uname { overflow: hidden; font-size: 12.5px; font-weight: 600; line-height: 14px; text-overflow: ellipsis; white-space: nowrap; }\n.hb-swk-mail { overflow: hidden; color: #8f8f8f; font-size: 10.5px; line-height: 12px; text-overflow: ellipsis; white-space: nowrap; }\n.hb-swk-menu { margin: 0; padding: 0; list-style: none; }\n.hb-swk-mi {\n  display: flex;\n  align-items: center;\n  width: 100%;\n  height: 30px;\n  margin: 0;\n  padding: 0 10px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #d4d4d4;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n}\n.hb-swk-mi:hover, .hb-swk-mi:focus-visible { background: #232323; color: #ffffff; outline: 0; }\n.hb-swk-mi[data-danger=\"true\"] { color: #ff7a85; }\n@keyframes hb-swk-pop {\n  from { opacity: 0; transform: translate3d(0, -4px, 0) scale(.97); }\n  to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }\n}\n@keyframes hb-swk-grow {\n  from { transform: scaleX(0); }\n  to { transform: scaleX(var(--hb-swk-p, 0)); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-swk-switch, .hb-swk-item, .hb-swk-chev, .hb-swk-fold, .hb-swk-up, .hb-swk-user, .hb-swk-fhead { transition: none; }\n  .hb-swk-pop, .hb-swk-fill { animation: none; }\n}\n`;\n\nfunction hueOf(value: string) {\n  let h = 11;\n  for (let i = 0; i < value.length; i += 1) h = (Math.imul(h, 31) + value.charCodeAt(i)) >>> 0;\n  return h % 360;\n}\n\nfunction initialsOf(name: string) {\n  const parts = name.trim().split(/\\s+/).filter(Boolean);\n  if (parts.length === 0) return \"?\";\n  const last = parts.length > 1 ? parts[parts.length - 1].charAt(0) : \"\";\n  return `${parts[0].charAt(0)}${last}`.toUpperCase();\n}\n\nfunction spaceColor(space: SidebarWorkspaceSpace) {\n  return space.color ?? `hsl(${hueOf(space.name)} 70% 52%)`;\n}\n\nexport function SidebarWorkspace({\n  workspaces = defaultWorkspaces,\n  workspace,\n  defaultWorkspace,\n  onWorkspaceChange,\n  onCreateWorkspace,\n  sections = defaultSections,\n  favorites = defaultFavorites,\n  favoritesLabel = \"Favorites\",\n  defaultFavoritesOpen = true,\n  active,\n  defaultActive,\n  onChange,\n  usage = defaultUsage,\n  upgradeLabel = \"Upgrade\",\n  onUpgrade,\n  user = defaultUser,\n  userMenu = defaultMenu,\n  onUserMenuSelect,\n  width = 260,\n  rowHeight = 32,\n  color = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: SidebarWorkspaceProps) {\n  const uid = React.useId();\n  const topRef = React.useRef<HTMLDivElement>(null);\n  const userRef = React.useRef<HTMLDivElement>(null);\n  const switchRef = React.useRef<HTMLButtonElement>(null);\n  const listRef = React.useRef<HTMLUListElement>(null);\n  const userBtnRef = React.useRef<HTMLButtonElement>(null);\n  const menuRef = React.useRef<HTMLUListElement>(null);\n  const [innerWs, setInnerWs] = React.useState(defaultWorkspace ?? workspaces[0]?.id ?? \"\");\n  const [innerActive, setInnerActive] = React.useState(defaultActive ?? sections[0]?.items[0]?.id ?? \"\");\n  const [switchOpen, setSwitchOpen] = React.useState(false);\n  const [menuOpen, setMenuOpen] = React.useState(false);\n  const [hi, setHi] = React.useState(0);\n  const [favOpen, setFavOpen] = React.useState(defaultFavoritesOpen);\n  const currentWs = workspace ?? innerWs;\n  const current = active ?? innerActive;\n  const space = workspaces.find((w) => w.id === currentWs) ?? workspaces[0];\n\n  React.useEffect(() => {\n    if (switchOpen) listRef.current?.focus();\n  }, [switchOpen]);\n\n  React.useEffect(() => {\n    if (menuOpen) menuRef.current?.querySelector<HTMLElement>(\"[role=menuitem]\")?.focus();\n  }, [menuOpen]);\n\n  React.useEffect(() => {\n    if (!switchOpen && !menuOpen) return;\n    const onDown = (e: PointerEvent) => {\n      const t = e.target as Node;\n      if (switchOpen && topRef.current && !topRef.current.contains(t)) setSwitchOpen(false);\n      if (menuOpen && userRef.current && !userRef.current.contains(t)) setMenuOpen(false);\n    };\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => document.removeEventListener(\"pointerdown\", onDown);\n  }, [switchOpen, menuOpen]);\n\n  function select(id: string) {\n    if (active === undefined) setInnerActive(id);\n    onChange?.(id);\n  }\n\n  function openSwitcher() {\n    setHi(Math.max(0, workspaces.findIndex((w) => w.id === currentWs)));\n    setMenuOpen(false);\n    setSwitchOpen(true);\n  }\n\n  function chooseWorkspace(id: string) {\n    if (workspace === undefined) setInnerWs(id);\n    onWorkspaceChange?.(id);\n    setSwitchOpen(false);\n    switchRef.current?.focus();\n  }\n\n  function handleListKey(e: React.KeyboardEvent<HTMLUListElement>) {\n    const last = workspaces.length - 1;\n    if (e.key === \"ArrowDown\") {\n      e.preventDefault();\n      setHi((v) => Math.min(last, v + 1));\n    } else if (e.key === \"ArrowUp\") {\n      e.preventDefault();\n      setHi((v) => Math.max(0, v - 1));\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      setHi(0);\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      setHi(last);\n    } else if (e.key === \"Enter\" || e.key === \" \") {\n      e.preventDefault();\n      const w = workspaces[hi];\n      if (w) chooseWorkspace(w.id);\n    } else if (e.key === \"Escape\") {\n      e.preventDefault();\n      e.stopPropagation();\n      setSwitchOpen(false);\n      switchRef.current?.focus();\n    } else if (e.key === \"Tab\") {\n      setSwitchOpen(false);\n    }\n  }\n\n  function handleMenuKey(e: React.KeyboardEvent<HTMLUListElement>) {\n    const items = Array.from(menuRef.current?.querySelectorAll<HTMLElement>(\"[role=menuitem]\") ?? []);\n    const at = items.indexOf(document.activeElement as HTMLElement);\n    if (e.key === \"ArrowDown\") {\n      e.preventDefault();\n      items[Math.min(items.length - 1, at + 1)]?.focus();\n    } else if (e.key === \"ArrowUp\") {\n      e.preventDefault();\n      items[Math.max(0, at - 1)]?.focus();\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      items[0]?.focus();\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      items[items.length - 1]?.focus();\n    } else if (e.key === \"Escape\") {\n      e.preventDefault();\n      e.stopPropagation();\n      setMenuOpen(false);\n      userBtnRef.current?.focus();\n    } else if (e.key === \"Tab\") {\n      setMenuOpen(false);\n    }\n  }\n\n  const pct = usage && usage.total > 0 ? Math.max(0, Math.min(1, usage.used / usage.total)) : 0;\n  const vars = { \"--hb-swk-w\": `${width}px`, \"--hb-swk-row\": `${rowHeight}px`, \"--hb-swk-accent\": color, ...style } as React.CSSProperties;\n  const listId = `${uid}-ws`;\n\n  return (\n    <aside className={`hb-swk ${className}`} style={vars} {...rest}>\n      <style href=\"hb-sidebar-workspace\" precedence=\"default\">{css}</style>\n      <div ref={topRef} className=\"hb-swk-top\">\n        {space ? (\n          <button\n            ref={switchRef}\n            type=\"button\"\n            className=\"hb-swk-switch\"\n            aria-haspopup=\"listbox\"\n            aria-expanded={switchOpen}\n            aria-controls={switchOpen ? listId : undefined}\n            aria-label={`Workspace: ${space.name}`}\n            onClick={() => (switchOpen ? setSwitchOpen(false) : openSwitcher())}\n            onKeyDown={(e) => {\n              if (e.key === \"ArrowDown\" && !switchOpen) {\n                e.preventDefault();\n                openSwitcher();\n              }\n            }}\n          >\n            <span className=\"hb-swk-mark\" aria-hidden=\"true\" style={{ \"--hb-swk-c\": spaceColor(space) } as React.CSSProperties}>\n              {space.name.charAt(0).toUpperCase()}\n            </span>\n            <span className=\"hb-swk-who\">\n              <span className=\"hb-swk-wname\">{space.name}</span>\n              {space.plan ? <span className=\"hb-swk-wplan\">{space.plan}</span> : null}\n            </span>\n            <svg className=\"hb-swk-caret\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n              <path d=\"M5 6.5L8 3.5l3 3M5 9.5l3 3 3-3\" />\n            </svg>\n          </button>\n        ) : null}\n        {switchOpen ? (\n          <div className=\"hb-swk-pop\">\n            <ul\n              ref={listRef}\n              id={listId}\n              className=\"hb-swk-list\"\n              role=\"listbox\"\n              tabIndex={-1}\n              aria-label=\"Workspaces\"\n              aria-activedescendant={`${listId}-${workspaces[hi]?.id}`}\n              onKeyDown={handleListKey}\n            >\n              {workspaces.map((w, i) => (\n                <li\n                  key={w.id}\n                  id={`${listId}-${w.id}`}\n                  className=\"hb-swk-opt\"\n                  role=\"option\"\n                  aria-selected={w.id === currentWs}\n                  data-hi={i === hi}\n                  onMouseEnter={() => setHi(i)}\n                  onClick={() => chooseWorkspace(w.id)}\n                >\n                  <span className=\"hb-swk-mark\" aria-hidden=\"true\" style={{ \"--hb-swk-c\": spaceColor(w) } as React.CSSProperties}>\n                    {w.name.charAt(0).toUpperCase()}\n                  </span>\n                  <span className=\"hb-swk-who\">\n                    <span className=\"hb-swk-wname\">{w.name}</span>\n                    {w.plan ? <span className=\"hb-swk-wplan\">{w.plan}</span> : null}\n                  </span>\n                  {w.id === currentWs ? (\n                    <svg className=\"hb-swk-check\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                      <path d=\"M3.5 8.5l3 3 6-7\" />\n                    </svg>\n                  ) : null}\n                </li>\n              ))}\n            </ul>\n            {onCreateWorkspace ? (\n              <>\n                <div className=\"hb-swk-sep\" />\n                <button\n                  type=\"button\"\n                  className=\"hb-swk-create\"\n                  onClick={() => {\n                    setSwitchOpen(false);\n                    onCreateWorkspace();\n                  }}\n                >\n                  <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                    <path d=\"M7 2.5v9M2.5 7h9\" />\n                  </svg>\n                  Create workspace\n                </button>\n              </>\n            ) : null}\n          </div>\n        ) : null}\n      </div>\n      <div className=\"hb-swk-mid\">\n        <nav aria-label=\"Workspace\">\n          {sections.map((section, si) => (\n            <div key={section.label ?? si} className=\"hb-swk-sec\">\n              {section.label ? <div className=\"hb-swk-label\">{section.label}</div> : null}\n              <ul className=\"hb-swk-items\" role=\"list\">\n                {section.items.map((item) => {\n                  const common = {\n                    className: \"hb-swk-item\",\n                    \"aria-current\": item.id === current ? (\"page\" as const) : undefined,\n                    onClick: () => select(item.id),\n                  };\n                  const body = (\n                    <>\n                      <span className=\"hb-swk-ico\" aria-hidden=\"true\">\n                        {item.icon ?? <SidebarWorkspaceIcon name=\"folder\" />}\n                      </span>\n                      <span className=\"hb-swk-text\">{item.label}</span>\n                      {item.count !== undefined && item.count !== \"\" ? <span className=\"hb-swk-count\">{item.count}</span> : null}\n                    </>\n                  );\n                  return (\n                    <li key={item.id}>\n                      {item.href ? (\n                        <a href={item.href} {...common}>\n                          {body}\n                        </a>\n                      ) : (\n                        <button type=\"button\" {...common}>\n                          {body}\n                        </button>\n                      )}\n                    </li>\n                  );\n                })}\n              </ul>\n            </div>\n          ))}\n          {favorites.length > 0 ? (\n            <div className=\"hb-swk-fav\">\n              <button\n                type=\"button\"\n                className=\"hb-swk-fhead\"\n                aria-expanded={favOpen}\n                aria-controls={`${uid}-fav`}\n                onClick={() => setFavOpen((v) => !v)}\n              >\n                <svg className=\"hb-swk-chev\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                  <path d=\"M6 3.5L10.5 8 6 12.5\" />\n                </svg>\n                {favoritesLabel}\n              </button>\n              <div id={`${uid}-fav`} className=\"hb-swk-fold\" data-open={favOpen} inert={!favOpen}>\n                <div className=\"hb-swk-fin\">\n                  <ul className=\"hb-swk-items\" role=\"list\">\n                    {favorites.map((fav) => (\n                      <li key={fav.id}>\n                        <button\n                          type=\"button\"\n                          className=\"hb-swk-item hb-swk-fav-item\"\n                          aria-current={fav.id === current ? \"page\" : undefined}\n                          onClick={() => select(fav.id)}\n                        >\n                          <span className=\"hb-swk-dot\" aria-hidden=\"true\" style={fav.color ? ({ \"--hb-swk-c\": fav.color } as React.CSSProperties) : undefined} />\n                          <span className=\"hb-swk-text\">{fav.label}</span>\n                        </button>\n                      </li>\n                    ))}\n                  </ul>\n                </div>\n              </div>\n            </div>\n          ) : null}\n        </nav>\n      </div>\n      <div className=\"hb-swk-bottom\">\n        {usage ? (\n          <div className=\"hb-swk-usage\">\n            <div className=\"hb-swk-urow\">\n              <span className=\"hb-swk-ulabel\">{usage.label}</span>\n              <button type=\"button\" className=\"hb-swk-up\" onClick={onUpgrade}>\n                {upgradeLabel}\n              </button>\n            </div>\n            <div\n              className=\"hb-swk-bar\"\n              role=\"progressbar\"\n              aria-label={usage.label}\n              aria-valuemin={0}\n              aria-valuemax={usage.total}\n              aria-valuenow={usage.used}\n              aria-valuetext={usage.caption}\n            >\n              <span className=\"hb-swk-fill\" data-warn={pct >= 0.85} style={{ \"--hb-swk-p\": pct.toFixed(3) } as React.CSSProperties} />\n            </div>\n            {usage.caption ? <div className=\"hb-swk-cap\">{usage.caption}</div> : null}\n          </div>\n        ) : null}\n        {user ? (\n          <div ref={userRef} className=\"hb-swk-userwrap\">\n            {menuOpen ? (\n              <div className=\"hb-swk-pop\" data-up=\"true\">\n                <ul ref={menuRef} className=\"hb-swk-menu\" role=\"menu\" aria-label={user.name} onKeyDown={handleMenuKey}>\n                  {userMenu.map((m) => (\n                    <li key={m.id} role=\"none\">\n                      <button\n                        type=\"button\"\n                        role=\"menuitem\"\n                        className=\"hb-swk-mi\"\n                        data-danger={m.danger ? \"true\" : undefined}\n                        onClick={() => {\n                          setMenuOpen(false);\n                          userBtnRef.current?.focus();\n                          onUserMenuSelect?.(m.id);\n                        }}\n                      >\n                        {m.label}\n                      </button>\n                    </li>\n                  ))}\n                </ul>\n              </div>\n            ) : null}\n            <button\n              ref={userBtnRef}\n              type=\"button\"\n              className=\"hb-swk-user\"\n              aria-haspopup=\"menu\"\n              aria-expanded={menuOpen}\n              onClick={() => {\n                setSwitchOpen(false);\n                setMenuOpen((v) => !v);\n              }}\n            >\n              <span\n                className=\"hb-swk-avatar\"\n                aria-hidden=\"true\"\n                style={{\n                  background:\n                    user.color ?? `linear-gradient(135deg, hsl(${hueOf(user.name)} 75% 60%), hsl(${(hueOf(user.name) + 50) % 360} 70% 42%))`,\n                }}\n              >\n                {initialsOf(user.name)}\n              </span>\n              <span className=\"hb-swk-who\">\n                <span className=\"hb-swk-uname\">{user.name}</span>\n                {user.email ? <span className=\"hb-swk-mail\">{user.email}</span> : null}\n              </span>\n              <svg className=\"hb-swk-caret\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"M5 6.5L8 3.5l3 3M5 9.5l3 3 3-3\" />\n              </svg>\n            </button>\n          </div>\n        ) : null}\n      </div>\n    </aside>\n  );\n}\n"
    }
  ]
}