{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tabs-url-hash",
  "title": "Tabs URL Hash",
  "description": "Tabs whose active tab lives in location.hash, so links open the right tab, reload keeps it and Back steps through tabs, with the first render always on the first tab.",
  "registryDependencies": [
    "tabs"
  ],
  "files": [
    {
      "path": "registry/patterns/tabs-url-hash/tabs-url-hash.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { Tabs, TabsContent, TabsList, TabsTrigger } from \"@/components/ui/tabs\"\n\nexport interface HashTab {\n  value: string\n  label: string\n  content: React.ReactNode\n}\n\nexport interface TabsUrlHashProps {\n  tabs: HashTab[]\n}\n\nfunction readHash(values: string[], fallback: string) {\n  const hash =\n    typeof window === \"undefined\" ? \"\" : window.location.hash.slice(1)\n  return values.includes(hash) ? hash : fallback\n}\n\n/**\n * Tabs that live in the URL. The active tab is written to `location.hash`\n * (`#billing`), so a link opens the right tab, reload keeps it, and the Back\n * button steps through tabs. An unknown hash falls back to the first tab, and\n * the first render always shows the first tab so server and client markup agree.\n */\nexport function TabsUrlHash({ tabs }: TabsUrlHashProps) {\n  const values = tabs.map((t) => t.value)\n  const [value, setValue] = React.useState(values[0])\n\n  React.useEffect(() => {\n    setValue(readHash(values, values[0]))\n    const onHash = () => setValue(readHash(values, values[0]))\n    window.addEventListener(\"hashchange\", onHash)\n    return () => window.removeEventListener(\"hashchange\", onHash)\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [values.join(\"|\")])\n\n  return (\n    <Tabs\n      value={value}\n      onValueChange={(next) => {\n        setValue(next)\n        window.location.hash = next\n      }}\n    >\n      <TabsList>\n        {tabs.map((t) => (\n          <TabsTrigger key={t.value} value={t.value}>\n            {t.label}\n          </TabsTrigger>\n        ))}\n      </TabsList>\n      {tabs.map((t) => (\n        <TabsContent key={t.value} value={t.value}>\n          <div id={t.value}>{t.content}</div>\n        </TabsContent>\n      ))}\n    </Tabs>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}