{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "casework-work-shell",
  "title": "Casework work shell",
  "description": "The staff work shell: one dense header, a sidebar that is a plain list of links, the jump palette and the shortcuts.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0",
    "lucide-react@1.43.0"
  ],
  "registryDependencies": [
    "@registrystack/casework-command-palette",
    "@registrystack/casework-content",
    "@registrystack/casework-shared",
    "@registrystack/casework-shortcuts",
    "@registrystack/lib-content",
    "@registrystack/lib-format",
    "@registrystack/ui-button",
    "@registrystack/ui-dropdown-menu",
    "@registrystack/ui-kbd",
    "@registrystack/ui-sheet",
    "@registrystack/ui-tooltip"
  ],
  "files": [
    {
      "path": "casework/work-shell.tsx",
      "content": "import {\n  useEffect,\n  useMemo,\n  useRef,\n  useState,\n  type ReactNode,\n  type RefObject,\n} from \"react\";\nimport {\n  ChevronDown,\n  ChevronRight,\n  CircleUserRound,\n  LogOut,\n  UserRoundCog,\n  Menu,\n  Search,\n  type LucideIcon,\n} from \"lucide-react\";\nimport { useSignOut } from \"@registrystack/app-runtime/react\";\nimport { Button } from \"@/components/ui/button\";\nimport {\n  DropdownMenu,\n  DropdownMenuCheckboxItem,\n  DropdownMenuContent,\n  DropdownMenuGroup,\n  DropdownMenuItem,\n  DropdownMenuLabel,\n  DropdownMenuSeparator,\n  DropdownMenuTrigger,\n} from \"@/components/ui/dropdown-menu\";\nimport { Kbd } from \"@/components/ui/kbd\";\nimport {\n  Sheet,\n  SheetContent,\n  SheetHeader,\n  SheetTitle,\n} from \"@/components/ui/sheet\";\nimport { TooltipProvider } from \"@/components/ui/tooltip\";\nimport { useCaseworkContent } from \"@/blocks/casework/casework-content\";\nimport { useLocale } from \"@/blocks/lib/content\";\nimport { fill } from \"@/blocks/lib/format\";\nimport { Notice, caseworkLocalZone } from \"@/blocks/casework/shared\";\nimport { CommandPalette, type Place } from \"@/blocks/casework/command-palette\";\nimport {\n  modifierLabel,\n  ShortcutsHelp,\n  ShortcutsProvider,\n  useShortcut,\n  useShortcutsSetting,\n} from \"@/blocks/casework/shortcuts\";\n\n/**\n * The staff work shell: a dark sidebar that is a plain list of places, one\n * dense header with the breadcrumb, search and account, and the page. It is built for the officer who lives in it all day,\n * so it spends no height on a service name or a signed-in line: the account\n * menu carries those, the palette and the shortcuts carry the navigation.\n * Which places exist, which one is current for a route, and where a route\n * sends the officer are all decisions specific to a session's role; the\n * caller makes them and hands this shell the result.\n */\n\nexport interface NavItem extends Place {\n  icon: LucideIcon;\n  /** Paths under which this place is the current one, beyond its own. */\n  under?: string[];\n}\n\nexport type NavGroup = NavItem[];\n\n/** Ends the session and signs the officer in again as another account. */\nexport interface SwitchAccountAction {\n  label: string;\n  /** Rejects when the sign-out is refused, so the officer stays signed in and is told. */\n  run: () => Promise<void>;\n}\n\n/**\n * The current place is the one whose path, or one of the paths it stands\n * under, is the longest prefix of the route. Query parameters belong to the\n * page and never change which place is current.\n */\nexport function currentPlace(items: NavItem[], path: string): NavItem | null {\n  let best: NavItem | null = null;\n  let bestLength = -1;\n  for (const item of items) {\n    for (const prefix of [item.path, ...(item.under ?? [])]) {\n      const matches =\n        prefix === \"/\"\n          ? path === \"/\"\n          : path === prefix || path.startsWith(`${prefix}/`);\n      if (matches && prefix.length > bestLength) {\n        best = item;\n        bestLength = prefix.length;\n      }\n    }\n  }\n  return best;\n}\n\n/**\n * The brand at the head of the sidebar: a mark of three leaning bars, the\n * service name and the beta chip.\n */\nfunction Brand({ brand, href }: { brand: string; href: string }) {\n  const c = useCaseworkContent();\n  return (\n    <a href={href} className=\"brand\">\n      <svg\n        className=\"work-brand-mark\"\n        viewBox=\"0 0 28 28\"\n        width=\"28\"\n        height=\"28\"\n        aria-hidden=\"true\"\n      >\n        <path d=\"M6 20 9 8h3.5L9.5 20zM12 20l3-12h3.5L15.5 20zM18 20l3-12h3.5L21.5 20z\" />\n      </svg>\n      <span className=\"work-brand-name\">{brand}</span>\n      <span className=\"beta\">{c.beta}</span>\n    </a>\n  );\n}\n\n/**\n * The places, grouped by the dividers between them. The sidebar shows them on\n * a wide screen and the menu drawer on a narrow one; only one is ever shown,\n * so the page always has exactly one main navigation.\n */\nfunction Places({\n  groups,\n  current,\n  hrefFor,\n  onNavigate,\n}: {\n  groups: NavGroup[];\n  current: NavItem | null;\n  hrefFor: (path: string) => string;\n  onNavigate?: () => void;\n}) {\n  const c = useCaseworkContent();\n  return (\n    <nav aria-label={c.navMain} className=\"work-places\">\n      {groups.map((group, index) => (\n        <div key={index} className=\"work-nav-group\">\n          {group.map((item) => (\n            <a\n              key={item.path}\n              href={hrefFor(item.path)}\n              aria-current={current === item ? \"page\" : undefined}\n              onClick={onNavigate}\n            >\n              <item.icon size={16} aria-hidden=\"true\" />\n              {item.label}\n            </a>\n          ))}\n        </div>\n      ))}\n    </nav>\n  );\n}\n\n/**\n * The signed-in officer's own corner: their name and time zone, the caller's\n * own choices, the switch for single-key shortcuts, switching account where\n * the caller offers it, and sign-out. A failed sign-out or switch leaves the\n * officer signed in and says so; it does not stop them working.\n */\nfunction AccountMenu({\n  displayName,\n  container,\n  choices,\n  switchAccount,\n  renderSignOutError,\n}: {\n  displayName?: string;\n  container: RefObject<HTMLElement | null>;\n  choices?: ReactNode;\n  switchAccount?: SwitchAccountAction;\n  /** Renders the host's own error when sign-out fails. Falls back to a generic notice when omitted. */\n  renderSignOutError?: (error: unknown) => ReactNode;\n}) {\n  const c = useCaseworkContent();\n  const [shortcuts, setShortcuts] = useShortcutsSetting();\n  const signOut = useSignOut();\n  const [error, setError] = useState<unknown>(null);\n  const name = displayName ?? c.account;\n  return (\n    <>\n      <DropdownMenu>\n        <DropdownMenuTrigger\n          render={\n            <Button\n              variant=\"ghost\"\n              size=\"sm\"\n              className=\"work-account\"\n              aria-label={name}\n            />\n          }\n        >\n          <CircleUserRound aria-hidden=\"true\" className=\"work-account-icon\" />\n          <span>{name}</span>\n          <ChevronDown size={14} aria-hidden=\"true\" />\n        </DropdownMenuTrigger>\n        <DropdownMenuContent\n          align=\"end\"\n          className=\"work-account-menu\"\n          container={container}\n        >\n          <DropdownMenuGroup>\n            <DropdownMenuLabel>\n              <span className=\"work-account-name\">{name}</span>\n              <span className=\"work-account-zone\">{caseworkLocalZone()}</span>\n            </DropdownMenuLabel>\n          </DropdownMenuGroup>\n          <DropdownMenuSeparator />\n          {choices}\n          <DropdownMenuCheckboxItem\n            checked={shortcuts}\n            onCheckedChange={setShortcuts}\n          >\n            {c.shortcutsSetting}\n          </DropdownMenuCheckboxItem>\n          <DropdownMenuSeparator />\n          {switchAccount && (\n            <DropdownMenuItem\n              onClick={() => void switchAccount.run().catch(setError)}\n            >\n              <UserRoundCog size={16} aria-hidden=\"true\" />\n              {switchAccount.label}\n            </DropdownMenuItem>\n          )}\n          <DropdownMenuItem onClick={() => void signOut().catch(setError)}>\n            <LogOut size={16} aria-hidden=\"true\" />\n            {c.signOut}\n          </DropdownMenuItem>\n        </DropdownMenuContent>\n      </DropdownMenu>\n      {error != null &&\n        (renderSignOutError ? (\n          renderSignOutError(error)\n        ) : (\n          <Notice tone=\"warning\">{c.signOutFailed}</Notice>\n        ))}\n    </>\n  );\n}\n\nfunction Frame({\n  displayName,\n  brand,\n  description,\n  accountChoices,\n  switchAccount,\n  groups,\n  current,\n  route,\n  hrefFor,\n  navigate,\n  renderSignOutError,\n  children,\n}: {\n  displayName?: string;\n  brand: string;\n  description?: string;\n  accountChoices?: ReactNode;\n  switchAccount?: SwitchAccountAction;\n  groups: NavGroup[];\n  current: NavItem | null;\n  route: string;\n  hrefFor: (path: string) => string;\n  navigate: (path: string) => void;\n  renderSignOutError?: (error: unknown) => ReactNode;\n  children: ReactNode;\n}) {\n  const c = useCaseworkContent();\n  const locale = useLocale();\n  const items = useMemo(() => groups.flat(), [groups]);\n  const [paletteOpen, setPaletteOpen] = useState(false);\n  const [helpOpen, setHelpOpen] = useState(false);\n  const [menuOpen, setMenuOpen] = useState(false);\n  // The account menu opens inside the header, and so inside its landmark.\n  const header = useRef<HTMLElement>(null);\n  // Any route change, a link in the drawer or a shortcut, closes the drawer.\n  useEffect(() => setMenuOpen(false), [route]);\n  useShortcut({ key: \"k\", label: c.shortcutGoTo, chord: \"mod\" }, () =>\n    setPaletteOpen(true),\n  );\n  useShortcut({ key: \"?\", label: c.shortcutHelp }, () => setHelpOpen(true));\n  const [online, setOnline] = useState(navigator.onLine);\n  useEffect(() => {\n    const update = () => setOnline(navigator.onLine);\n    window.addEventListener(\"online\", update);\n    window.addEventListener(\"offline\", update);\n    return () => {\n      window.removeEventListener(\"online\", update);\n      window.removeEventListener(\"offline\", update);\n    };\n  }, []);\n  return (\n    <div className=\"work-shell\">\n      <a\n        className=\"skip-link\"\n        href=\"#main\"\n        onClick={(e) => {\n          e.preventDefault();\n          document.getElementById(\"main\")?.focus();\n        }}\n      >\n        {c.skip}\n      </a>\n      <aside className=\"work-sidebar\" aria-label={c.staffName}>\n        <div className=\"work-sidebar-inner\">\n          <Brand brand={brand} href={hrefFor(\"/\")} />\n          <p className=\"work-workspace\">{c.staffName}</p>\n          {description && (\n            <p className=\"work-workspace-description\">{description}</p>\n          )}\n          <Places groups={groups} current={current} hrefFor={hrefFor} />\n          <p className=\"work-sidebar-note\">{c.footerNote}</p>\n        </div>\n      </aside>\n      <div className=\"work-column\">\n        <header ref={header} className=\"work-header\">\n          <Button\n            variant=\"ghost\"\n            size=\"icon\"\n            className=\"work-menu\"\n            aria-label={c.navMenu}\n            onClick={() => setMenuOpen(true)}\n          >\n            <Menu aria-hidden=\"true\" />\n          </Button>\n          <a href={hrefFor(\"/\")} className=\"work-header-brand\">\n            {brand}\n          </a>\n          <p className=\"work-crumb\">\n            <span>{brand}</span>\n            {current && (\n              <>\n                <ChevronRight size={14} aria-hidden=\"true\" />\n                <span>{current.label}</span>\n              </>\n            )}\n          </p>\n          <button\n            type=\"button\"\n            className=\"work-search\"\n            onClick={() => setPaletteOpen(true)}\n            aria-label={c.goTo}\n          >\n            <Search size={15} aria-hidden=\"true\" />\n            <span aria-hidden=\"true\">{c.goToPlaceholder}</span>\n            <Kbd aria-hidden=\"true\">\n              {fill(\n                c.shortcutChord,\n                { modifier: modifierLabel(c), key: \"K\" },\n                locale,\n              )}\n            </Kbd>\n          </button>\n          <AccountMenu\n            displayName={displayName}\n            container={header}\n            choices={accountChoices}\n            switchAccount={switchAccount}\n            renderSignOutError={renderSignOutError}\n          />\n        </header>\n        <main id=\"main\" tabIndex={-1} className=\"work-main\">\n          {!online && <Notice tone=\"warning\">{c.offline}</Notice>}\n          {children}\n        </main>\n      </div>\n      <Sheet open={menuOpen} onOpenChange={setMenuOpen}>\n        <SheetContent\n          side=\"inline-start\"\n          closeLabel={c.close}\n          className=\"work-menu-sheet w-72\"\n        >\n          <SheetHeader>\n            <SheetTitle>{brand}</SheetTitle>\n          </SheetHeader>\n          <Places\n            groups={groups}\n            current={current}\n            hrefFor={hrefFor}\n            onNavigate={() => setMenuOpen(false)}\n          />\n          <p className=\"work-sidebar-note\">{c.footerNote}</p>\n        </SheetContent>\n      </Sheet>\n      <CommandPalette\n        open={paletteOpen}\n        onOpenChange={setPaletteOpen}\n        places={items}\n        navigate={navigate}\n      />\n      <ShortcutsHelp open={helpOpen} onOpenChange={setHelpOpen} />\n    </div>\n  );\n}\n\nexport interface WorkShellProps {\n  /** The signed-in officer's display name, shown in the header and menu. */\n  displayName?: string;\n  /** The service name, shown in the header and the mobile drawer. */\n  brand: string;\n  /** What the app is for, shown under the workspace name in the sidebar. */\n  description?: string;\n  /**\n   * Further choices in the account menu, above the shortcuts setting, each\n   * group ending in a separator. They render only while the menu is open.\n   */\n  accountChoices?: ReactNode;\n  /** Offers switching account in the account menu where given. */\n  switchAccount?: SwitchAccountAction;\n  /** The places this session can go, grouped by the dividers between them. */\n  groups: NavGroup[];\n  /** The place the current route stands for, or null off every place. */\n  current: NavItem | null;\n  /** The current route, so a navigation closes the mobile drawer. */\n  route: string;\n  /** Builds an in-app link's href from its path. The shell assumes no router of its own. */\n  hrefFor: (path: string) => string;\n  /** Sends the officer to a path chosen outside a link, such as the palette. */\n  navigate: (path: string) => void;\n  /** Renders the host's own error when sign-out fails. Falls back to a generic notice when omitted. */\n  renderSignOutError?: (error: unknown) => ReactNode;\n  children: ReactNode;\n}\n\nexport function WorkShell({\n  displayName,\n  brand,\n  description,\n  accountChoices,\n  switchAccount,\n  groups,\n  current,\n  route,\n  hrefFor,\n  navigate,\n  renderSignOutError,\n  children,\n}: WorkShellProps) {\n  return (\n    <ShortcutsProvider>\n      <TooltipProvider>\n        <Frame\n          displayName={displayName}\n          brand={brand}\n          description={description}\n          accountChoices={accountChoices}\n          switchAccount={switchAccount}\n          groups={groups}\n          current={current}\n          route={route}\n          hrefFor={hrefFor}\n          navigate={navigate}\n          renderSignOutError={renderSignOutError}\n        >\n          {children}\n        </Frame>\n      </TooltipProvider>\n    </ShortcutsProvider>\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/casework/work-shell.tsx"
    }
  ],
  "type": "registry:block"
}