{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "language-suggestion-banner",
  "title": "Language Suggestion Banner",
  "description": "Offers a page in the visitor's own language, written in that language, with a picker for the others. It remembers the answer and only appears when it helps.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/language-suggestion-banner/language-suggestion-banner.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface LanguageOption {\n  /** Language code, e.g. \"tr\". */\n  code: string;\n  /** Its name in its own language, e.g. \"Türkçe\". */\n  name: string;\n  /** The offer, written in that language. */\n  message: string;\n  /** Label of the button, written in that language. */\n  action: string;\n  /** Label for staying put, written in that language. */\n  stay: string;\n  href?: string;\n}\n\nexport interface LanguageSuggestionBannerProps extends React.ComponentPropsWithoutRef<\"div\"> {\n  theme?: \"dark\" | \"light\";\n  /** Languages the site is available in. */\n  languages?: LanguageOption[];\n  /** The language of the page people are on. */\n  current?: string;\n  /** Force a language instead of reading the browser. */\n  detected?: string;\n  /** Key used to remember the answer. */\n  storageKey?: string;\n  /** Called with the language people picked. */\n  onSwitch?: (language: LanguageOption) => void;\n  onDismiss?: () => void;\n}\n\nconst PALETTES = {\n  dark: {\n    bar: \"#0F1011\",\n    surface: \"#161718\",\n    border: \"rgba(255,255,255,0.08)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.06)\",\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n    accent: \"#5E6AD2\",\n    shadow: \"0 8px 32px rgba(0,0,0,0.45)\",\n  },\n  light: {\n    bar: \"#FFFFFF\",\n    surface: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.1)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.05)\",\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n    accent: \"#5E6AD2\",\n    shadow: \"0 8px 28px rgba(8,9,10,0.12)\",\n  },\n};\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\n\n/** Folds its content away when closed, so a dismissed bar doesn't leave a gap. */\nfunction Collapse({\n  open,\n  onGone,\n  children,\n}: {\n  open: boolean;\n  onGone?: () => void;\n  children: React.ReactNode;\n}) {\n  return (\n    <div\n      className=\"grid motion-safe:transition-[grid-template-rows,opacity] motion-safe:duration-300\"\n      style={{ gridTemplateRows: open ? \"1fr\" : \"0fr\", opacity: open ? 1 : 0 }}\n      onTransitionEnd={(e) => {\n        if (!open && e.propertyName === \"grid-template-rows\") onGone?.();\n      }}\n    >\n      <div className=\"min-h-0 overflow-hidden\">{children}</div>\n    </div>\n  );\n}\n\nconst LANGUAGES: LanguageOption[] = [\n  {\n    code: \"en\",\n    name: \"English\",\n    message: \"This page is available in English.\",\n    action: \"Switch\",\n    stay: \"Stay here\",\n  },\n  {\n    code: \"tr\",\n    name: \"Türkçe\",\n    message: \"Bu sayfa Türkçe olarak da mevcut.\",\n    action: \"Geçiş yap\",\n    stay: \"Burada kal\",\n  },\n  {\n    code: \"de\",\n    name: \"Deutsch\",\n    message: \"Diese Seite gibt es auch auf Deutsch.\",\n    action: \"Wechseln\",\n    stay: \"Hier bleiben\",\n  },\n  {\n    code: \"es\",\n    name: \"Español\",\n    message: \"Esta página también está en español.\",\n    action: \"Cambiar\",\n    stay: \"Quedarme aquí\",\n  },\n];\n\nexport function LanguageSuggestionBanner({\n  theme = \"dark\",\n  languages = LANGUAGES,\n  current = \"en\",\n  detected,\n  storageKey = \"language-suggestion\",\n  onSwitch,\n  onDismiss,\n  className,\n  style,\n  ...props\n}: LanguageSuggestionBannerProps) {\n  const pal = PALETTES[theme];\n  const [open, setOpen] = React.useState(false);\n  const [code, setCode] = React.useState(detected ?? \"\");\n  const others = languages.filter((l) => l.code !== current);\n  const choice = others.find((l) => l.code === code) ?? others[0];\n\n  // Only the browser knows its language, so the banner decides after it mounts.\n  React.useEffect(() => {\n    const frame = requestAnimationFrame(() => {\n      const wanted = (detected ?? navigator.language).slice(0, 2);\n      let answered = false;\n      try {\n        answered = !!window.localStorage.getItem(storageKey);\n      } catch {\n        // Storage can be blocked. Asking again is the safe outcome.\n      }\n      const match =\n        wanted !== current && languages.some((l) => l.code === wanted);\n      setCode(wanted);\n      setOpen(match && (!answered || detected !== undefined));\n    });\n    return () => cancelAnimationFrame(frame);\n  }, [detected, current, languages, storageKey]);\n\n  const answer = (value: string) => {\n    try {\n      window.localStorage.setItem(storageKey, value);\n    } catch {\n      // Nothing to do: it will simply ask again next time.\n    }\n    setOpen(false);\n  };\n\n  if (!choice) return null;\n  return (\n    <Collapse open={open} onGone={onDismiss}>\n      <div\n        role=\"region\"\n        aria-label=\"Language suggestion\"\n        lang={choice.code}\n        className={`flex w-full flex-wrap items-center justify-center gap-x-3 gap-y-2 px-4 py-2.5 ${className ?? \"\"}`}\n        style={{\n          background: pal.bar,\n          boxShadow: `inset 0 -1px 0 ${pal.border}`,\n          color: pal.text,\n          fontFamily: FONT,\n          ...style,\n        }}\n        {...props}\n      >\n        <svg\n          width=\"15\"\n          height=\"15\"\n          viewBox=\"0 0 16 16\"\n          fill=\"none\"\n          stroke=\"currentColor\"\n          strokeWidth=\"1.3\"\n          aria-hidden=\"true\"\n          className=\"shrink-0\"\n          style={{ color: pal.sub }}\n        >\n          <circle cx=\"8\" cy=\"8\" r=\"6.5\" />\n          <path d=\"M1.5 8h13M8 1.5c2 1.8 3 4 3 6.5s-1 4.7-3 6.5c-2-1.8-3-4-3-6.5s1-4.7 3-6.5Z\" />\n        </svg>\n        <p className=\"m-0 text-[13px] tracking-[-0.011em]\">{choice.message}</p>\n        <label className=\"relative flex h-8 items-center\">\n          <span className=\"sr-only\">Language</span>\n          <select\n            value={choice.code}\n            onChange={(e) => setCode(e.target.value)}\n            className=\"h-8 cursor-pointer appearance-none rounded-full border-0 pr-7 pl-3 text-[13px] font-[510] outline-none focus-visible:ring-2\"\n            style={{ background: pal.chip, color: pal.text }}\n          >\n            {others.map((l) => (\n              <option key={l.code} value={l.code} style={{ color: \"#08090A\" }}>\n                {l.name}\n              </option>\n            ))}\n          </select>\n          <svg\n            width=\"8\"\n            height=\"8\"\n            viewBox=\"0 0 8 8\"\n            fill=\"none\"\n            stroke=\"currentColor\"\n            strokeWidth=\"1.5\"\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n            aria-hidden=\"true\"\n            className=\"pointer-events-none absolute right-3\"\n            style={{ color: pal.sub }}\n          >\n            <path d=\"m1 2.5 3 3 3-3\" />\n          </svg>\n        </label>\n        <button\n          type=\"button\"\n          onClick={() => {\n            answer(choice.code);\n            onSwitch?.(choice);\n            if (choice.href) window.location.href = choice.href;\n          }}\n          className=\"h-8 cursor-pointer rounded-full px-3.5 text-[13px] font-[510] transition-opacity hover:opacity-90\"\n          style={{ background: pal.btn, color: pal.btnText }}\n        >\n          {choice.action}\n        </button>\n        <button\n          type=\"button\"\n          onClick={() => answer(current)}\n          className=\"h-8 cursor-pointer rounded-full px-2.5 text-[13px] outline-none hover:underline focus-visible:ring-2\"\n          style={{ color: pal.sub }}\n        >\n          {choice.stay}\n        </button>\n      </div>\n    </Collapse>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}