{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shell-language-switch",
  "title": "Language switch",
  "description": "Chooses the language the app is read in among those the UI model offers, as a select or as a group of an account menu.",
  "dependencies": [
    "@registrystack/app-runtime@~0.43.0-next.0",
    "lucide-react@1.43.0"
  ],
  "registryDependencies": [
    "@registrystack/shell-content",
    "@registrystack/ui-dropdown-menu"
  ],
  "files": [
    {
      "path": "shell/language-switch.tsx",
      "content": "import { Languages } from \"lucide-react\";\nimport { languageName } from \"@registrystack/app-runtime\";\nimport { useLanguage, useModel } from \"@registrystack/app-runtime/react\";\nimport {\n  DropdownMenuGroup,\n  DropdownMenuLabel,\n  DropdownMenuRadioGroup,\n  DropdownMenuRadioItem,\n  DropdownMenuSeparator,\n} from \"@/components/ui/dropdown-menu\";\nimport { useShellContent } from \"@/blocks/shell/shell-content\";\n\nconst noLanguages: readonly string[] = [];\n\n/** The languages a UI model offers and the one the session's model is worded in. */\nexport interface OfferedLanguages {\n  language: string;\n  languages: readonly string[];\n}\n\n/**\n * The languages the UI model offers and the one the session's model is worded\n * in; none until the model is read, or when the UI model offers one language.\n */\nexport function useOfferedLanguages(): OfferedLanguages | undefined {\n  const model = useModel().data;\n  const languages = model?.languages ?? noLanguages;\n  return model?.language && languages.length > 1\n    ? { language: model.language, languages }\n    : undefined;\n}\n\n/**\n * Chooses the language the app is read in, among those the UI model offers,\n * each named in itself so a person finds their own whatever the page is in.\n */\nexport function LanguageSwitch() {\n  const c = useShellContent();\n  const offered = useOfferedLanguages();\n  const { choose } = useLanguage();\n  if (!offered) return null;\n  return (\n    <label className=\"language-switch\">\n      <Languages size={16} aria-hidden=\"true\" />\n      <span className=\"sr-only\">{c.language}</span>\n      <select\n        value={offered.language}\n        onChange={(event) => choose(event.target.value)}\n      >\n        {offered.languages.map((language) => (\n          <option key={language} value={language} lang={language}>\n            {languageName(language)}\n          </option>\n        ))}\n      </select>\n    </label>\n  );\n}\n\n/**\n * The same choice as a group of an account menu, followed by a separator. The\n * caller reads the languages with `useOfferedLanguages` where the menu itself\n * is mounted: a menu's content mounts on opening, and a read there would read\n * a model the host refused again.\n */\nexport function LanguageMenuGroup(offered: OfferedLanguages) {\n  const c = useShellContent();\n  const { choose } = useLanguage();\n  return (\n    <>\n      <DropdownMenuGroup>\n        <DropdownMenuLabel>{c.language}</DropdownMenuLabel>\n        <DropdownMenuRadioGroup\n          value={offered.language}\n          onValueChange={(language: string) => choose(language)}\n        >\n          {offered.languages.map((language) => (\n            <DropdownMenuRadioItem\n              key={language}\n              value={language}\n              lang={language}\n            >\n              {languageName(language)}\n            </DropdownMenuRadioItem>\n          ))}\n        </DropdownMenuRadioGroup>\n      </DropdownMenuGroup>\n      <DropdownMenuSeparator />\n    </>\n  );\n}\n",
      "type": "registry:block",
      "target": "@components/shell/language-switch.tsx"
    }
  ],
  "type": "registry:block"
}