{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "resource-wiki",
  "title": "Resource Wiki",
  "description": "A reusable Markdown resource/wiki block with search, SPA-style page navigation, copy and download actions, and a curved table-of-contents indicator.",
  "dependencies": [
    "@radix-ui/react-slot",
    "github-slugger",
    "lucide-react",
    "react-markdown",
    "rehype-highlight",
    "rehype-slug",
    "remark-gfm",
    "sonner"
  ],
  "registryDependencies": [
    "badge",
    "button",
    "dropdown-menu",
    "input",
    "scroll-area",
    "separator"
  ],
  "files": [
    {
      "path": "registry/corr/components/resource-wiki.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport GithubSlugger from \"github-slugger\"\nimport {\n  CheckIcon,\n  ChevronLeftIcon,\n  ChevronRightIcon,\n  CopyIcon,\n  DownloadIcon,\n  ExternalLinkIcon,\n  FileTextIcon,\n  LinkIcon,\n  MoreHorizontalIcon,\n  PanelLeftCloseIcon,\n  PanelLeftOpenIcon,\n  SearchIcon,\n} from \"lucide-react\"\nimport ReactMarkdown from \"react-markdown\"\nimport rehypeHighlight from \"rehype-highlight\"\nimport rehypeSlug from \"rehype-slug\"\nimport remarkGfm from \"remark-gfm\"\nimport { toast } from \"sonner\"\n\nimport { Badge } from \"@/components/ui/badge\"\nimport { Button } from \"@/components/ui/button\"\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuItem,\n  DropdownMenuTrigger,\n} from \"@/components/ui/dropdown-menu\"\nimport { Input } from \"@/components/ui/input\"\nimport { ScrollArea } from \"@/components/ui/scroll-area\"\nimport { Separator } from \"@/components/ui/separator\"\nimport { cn } from \"@/lib/utils\"\n\nexport type ResourcePage = {\n  slug: string\n  title: string\n  description: string\n  group: string\n  markdown: string\n  readTime?: string\n  updatedAt?: string\n}\n\nexport type ResourceWikiProps = {\n  pages: ResourcePage[]\n  activeSlug?: string\n  defaultSlug?: string\n  basePath?: string\n  headerOffset?: number\n  label?: string\n  badge?: string\n  className?: string\n  onNavigate?: (slug: string, hash?: string) => void\n}\n\ntype HeadingItem = {\n  id: string\n  title: string\n  level: number\n}\n\nfunction getPagePath(basePath: string, slug: string, hash?: string) {\n  const base = basePath.endsWith(\"/\") ? basePath.slice(0, -1) : basePath\n  return `${base}/${slug}${hash ? `#${hash}` : \"\"}`\n}\n\nfunction extractHeadings(markdown: string) {\n  const slugger = new GithubSlugger()\n  const headings: HeadingItem[] = []\n  const lines = markdown.split(\"\\n\")\n\n  for (const line of lines) {\n    const match = /^(#{2,3})\\s+(.+?)\\s*$/.exec(line)\n    if (!match) continue\n    const title = match[2]\n      .replace(/`([^`]+)`/g, \"$1\")\n      .replace(/\\[([^\\]]+)\\]\\([^)]+\\)/g, \"$1\")\n      .replace(/[*_~]/g, \"\")\n      .trim()\n\n    headings.push({\n      id: slugger.slug(title),\n      title,\n      level: match[1].length,\n    })\n  }\n\n  return headings\n}\n\nfunction groupPages(pages: ResourcePage[]) {\n  return pages.reduce<Record<string, ResourcePage[]>>((groups, page) => {\n    groups[page.group] = [...(groups[page.group] ?? []), page]\n    return groups\n  }, {})\n}\n\nfunction matchesQuery(page: ResourcePage, query: string) {\n  const words = query\n    .toLowerCase()\n    .split(/\\s+/)\n    .map((word) => word.trim())\n    .filter(Boolean)\n\n  if (words.length === 0) return true\n\n  const haystack =\n    `${page.title} ${page.description} ${page.group} ${page.markdown}`.toLowerCase()\n  return words.every((word) => haystack.includes(word))\n}\n\nfunction useCopiedLabel() {\n  const [copied, setCopied] = React.useState(false)\n\n  React.useEffect(() => {\n    if (!copied) return\n    const timeout = window.setTimeout(() => setCopied(false), 1400)\n    return () => window.clearTimeout(timeout)\n  }, [copied])\n\n  return [copied, setCopied] as const\n}\n\nfunction TocCurve({\n  headings,\n  activeId,\n  linkRefs,\n}: {\n  headings: HeadingItem[]\n  activeId?: string\n  linkRefs: React.MutableRefObject<Record<string, HTMLAnchorElement | null>>\n}) {\n  const containerRef = React.useRef<HTMLDivElement | null>(null)\n  const trackRef = React.useRef<SVGPathElement | null>(null)\n  const indicatorRef = React.useRef<SVGPathElement | null>(null)\n  const [path, setPath] = React.useState(\"\")\n\n  React.useLayoutEffect(() => {\n    function measure() {\n      const currentContainer = containerRef.current\n      if (!currentContainer) return\n      const bounds = currentContainer.getBoundingClientRect()\n      const points = headings\n        .map((heading) => {\n          const link = linkRefs.current[heading.id]\n          if (!link) return null\n          const rect = link.getBoundingClientRect()\n          const top = rect.top - bounds.top\n          const bottom = rect.bottom - bounds.top\n          const center = top + rect.height / 2\n          const x = 1 + Math.max(0, heading.level - 2) * 10\n          return { id: heading.id, top, bottom, center, x }\n        })\n        .filter(Boolean) as Array<{\n        id: string\n        top: number\n        bottom: number\n        center: number\n        x: number\n      }>\n\n      if (points.length === 0) {\n        setPath(\"\")\n        return\n      }\n\n      const [first] = points\n      const last = points[points.length - 1]\n      let nextPath = `M ${first.x} ${first.top} L ${first.x} ${first.center}`\n\n      for (let index = 1; index < points.length; index += 1) {\n        const previous = points[index - 1]\n        const point = points[index]\n        const middle = (previous.center + point.center) / 2\n        nextPath += ` C ${previous.x} ${middle}, ${point.x} ${middle}, ${point.x} ${point.center}`\n      }\n\n      nextPath += ` L ${last.x} ${last.bottom}`\n      setPath(nextPath)\n    }\n\n    measure()\n    const observer = new ResizeObserver(measure)\n    const container = containerRef.current\n    if (container) observer.observe(container)\n    Object.values(linkRefs.current).forEach((link) => {\n      if (link) observer.observe(link)\n    })\n    window.addEventListener(\"resize\", measure)\n\n    return () => {\n      observer.disconnect()\n      window.removeEventListener(\"resize\", measure)\n    }\n  }, [headings, linkRefs])\n\n  React.useEffect(() => {\n    const track = trackRef.current\n    const indicator = indicatorRef.current\n    if (!track || !indicator || !activeId) return\n\n    const link = linkRefs.current[activeId]\n    const container = containerRef.current\n    if (!link || !container) return\n\n    const total = track.getTotalLength()\n    const containerBounds = container.getBoundingClientRect()\n    const linkBounds = link.getBoundingClientRect()\n    const top = linkBounds.top - containerBounds.top\n    const bottom = linkBounds.bottom - containerBounds.top\n\n    function lengthAtY(currentTrack: SVGPathElement, y: number) {\n      let low = 0\n      let high = total\n      for (let index = 0; index < 20; index += 1) {\n        const middle = (low + high) / 2\n        if (currentTrack.getPointAtLength(middle).y < y) low = middle\n        else high = middle\n      }\n      return (low + high) / 2\n    }\n\n    const start = lengthAtY(track, top)\n    const end = lengthAtY(track, bottom)\n    indicator.style.strokeDasharray = `${Math.max(1, end - start)} ${total + 1}`\n    indicator.style.strokeDashoffset = `${-start}`\n  }, [activeId, headings, linkRefs, path])\n\n  return (\n    <div\n      ref={containerRef}\n      className=\"pointer-events-none absolute inset-y-0 left-0 w-8\"\n    >\n      {path ? (\n        <svg className=\"absolute inset-0 h-full w-full overflow-visible fill-none\">\n          <path\n            ref={trackRef}\n            d={path}\n            className=\"stroke-border\"\n            strokeWidth=\"1\"\n          />\n          <path\n            ref={indicatorRef}\n            d={path}\n            className=\"stroke-foreground transition-[stroke-dasharray,stroke-dashoffset] duration-300 ease-out motion-reduce:transition-none\"\n            strokeLinecap=\"round\"\n            strokeWidth=\"2\"\n          />\n        </svg>\n      ) : null}\n    </div>\n  )\n}\n\nfunction TableOfContents({\n  headings,\n  activeId,\n  onHeadingClick,\n}: {\n  headings: HeadingItem[]\n  activeId?: string\n  onHeadingClick: (id: string) => void\n}) {\n  const linkRefs = React.useRef<Record<string, HTMLAnchorElement | null>>({})\n\n  if (headings.length === 0) return null\n\n  return (\n    <nav aria-label=\"On this page\">\n      <div className=\"mb-3 text-xs font-medium text-muted-foreground\">\n        On this page\n      </div>\n      <div className=\"relative\">\n        <TocCurve headings={headings} activeId={activeId} linkRefs={linkRefs} />\n        <div className=\"relative grid\">\n          {headings.map((heading, index) => (\n            <a\n              key={heading.id}\n              ref={(node) => {\n                linkRefs.current[heading.id] = node\n              }}\n              href={`#${heading.id}`}\n              aria-current={activeId === heading.id ? \"location\" : undefined}\n              className={cn(\n                \"block rounded-sm py-1 text-xs leading-snug text-muted-foreground transition-colors hover:text-foreground\",\n                heading.level === 2 ? \"pl-4\" : \"pl-7\",\n                heading.level === 2 && index > 0 && \"mt-1\",\n                activeId === heading.id && \"font-medium text-foreground\"\n              )}\n              onClick={(event) => {\n                event.preventDefault()\n                onHeadingClick(heading.id)\n              }}\n            >\n              {heading.title}\n            </a>\n          ))}\n        </div>\n      </div>\n    </nav>\n  )\n}\n\nfunction ResourceMarkdown({\n  markdown,\n  onNavigate,\n}: {\n  markdown: string\n  onNavigate: (slug: string, hash?: string) => void\n}) {\n  return (\n    <ReactMarkdown\n      remarkPlugins={[remarkGfm]}\n      rehypePlugins={[rehypeSlug, rehypeHighlight]}\n      components={{\n        h1: () => null,\n        h2: ({ className, ...props }) => (\n          <h2\n            className={cn(\n              \"scroll-mt-28 pt-8 text-2xl font-semibold tracking-tight first:pt-0\",\n              className\n            )}\n            {...props}\n          />\n        ),\n        h3: ({ className, ...props }) => (\n          <h3\n            className={cn(\"scroll-mt-28 pt-6 text-lg font-semibold\", className)}\n            {...props}\n          />\n        ),\n        p: ({ className, ...props }) => (\n          <p\n            className={cn(\"text-sm leading-7 text-muted-foreground\", className)}\n            {...props}\n          />\n        ),\n        a: ({ href = \"\", children, className, ...props }) => {\n          const isMarkdownLink = href.endsWith(\".md\") || href.includes(\".md#\")\n          const isExternal = /^https?:\\/\\//.test(href)\n          const markdownTarget = isMarkdownLink\n            ? href.replace(/^\\.\\//, \"\").replace(/\\.md(#.*)?$/, \"$1\")\n            : \"\"\n          const [slug, hash] = markdownTarget.split(\"#\")\n\n          if (isMarkdownLink && slug) {\n            return (\n              <a\n                href={href}\n                className={cn(\n                  \"font-medium underline underline-offset-4\",\n                  className\n                )}\n                onClick={(event) => {\n                  event.preventDefault()\n                  onNavigate(slug, hash)\n                }}\n                {...props}\n              >\n                {children}\n              </a>\n            )\n          }\n\n          return (\n            <a\n              href={href}\n              className={cn(\n                \"font-medium underline underline-offset-4\",\n                className\n              )}\n              target={isExternal ? \"_blank\" : undefined}\n              rel={isExternal ? \"noopener noreferrer\" : undefined}\n              {...props}\n            >\n              {children}\n              {isExternal ? (\n                <ExternalLinkIcon className=\"ml-1 inline size-3 align-[-0.125em]\" />\n              ) : null}\n            </a>\n          )\n        },\n        ul: ({ className, ...props }) => (\n          <ul\n            className={cn(\"ml-5 list-disc text-sm leading-7\", className)}\n            {...props}\n          />\n        ),\n        ol: ({ className, ...props }) => (\n          <ol\n            className={cn(\"ml-5 list-decimal text-sm leading-7\", className)}\n            {...props}\n          />\n        ),\n        li: ({ className, ...props }) => (\n          <li\n            className={cn(\"pl-1 text-muted-foreground\", className)}\n            {...props}\n          />\n        ),\n        blockquote: ({ className, ...props }) => (\n          <blockquote\n            className={cn(\n              \"rounded-md border bg-muted/30 px-4 py-3 text-sm leading-7 text-muted-foreground\",\n              className\n            )}\n            {...props}\n          />\n        ),\n        table: ({ className, ...props }) => (\n          <div className=\"my-4 overflow-x-auto rounded-md border\">\n            <table\n              className={cn(\"w-full min-w-[36rem] text-sm\", className)}\n              {...props}\n            />\n          </div>\n        ),\n        th: ({ className, ...props }) => (\n          <th\n            className={cn(\n              \"border-b bg-muted/40 px-3 py-2 text-left text-xs font-medium\",\n              className\n            )}\n            {...props}\n          />\n        ),\n        td: ({ className, ...props }) => (\n          <td\n            className={cn(\n              \"border-b px-3 py-2 text-muted-foreground\",\n              className\n            )}\n            {...props}\n          />\n        ),\n        code: ({ className, children, ...props }) => {\n          const isBlock = String(children).includes(\"\\n\")\n\n          if (isBlock) {\n            return (\n              <code\n                className={cn(\"block text-xs leading-6\", className)}\n                {...props}\n              >\n                {children}\n              </code>\n            )\n          }\n\n          return (\n            <code\n              className={cn(\n                \"rounded bg-muted px-1.5 py-0.5 font-mono text-xs text-foreground\",\n                className\n              )}\n              {...props}\n            >\n              {children}\n            </code>\n          )\n        },\n        pre: ({ className, children, ...props }) => (\n          <pre\n            className={cn(\n              \"my-4 overflow-x-auto rounded-md border bg-muted/30 p-4\",\n              className\n            )}\n            {...props}\n          >\n            {children}\n          </pre>\n        ),\n        hr: (props) => <Separator className=\"my-8\" {...props} />,\n      }}\n    >\n      {markdown}\n    </ReactMarkdown>\n  )\n}\n\nfunction ResourceActionButton({\n  copied,\n  children,\n  ...props\n}: React.ComponentProps<typeof Button> & {\n  copied?: boolean\n}) {\n  return (\n    <Button size=\"sm\" variant=\"outline\" {...props}>\n      {copied ? <CheckIcon className=\"size-4\" /> : null}\n      {children}\n    </Button>\n  )\n}\n\nexport function ResourceWiki({\n  pages,\n  activeSlug,\n  defaultSlug,\n  basePath = \"/resources\",\n  headerOffset = 57,\n  label = \"Resources\",\n  badge,\n  className,\n  onNavigate,\n}: ResourceWikiProps) {\n  const [internalSlug, setInternalSlug] = React.useState(\n    defaultSlug ?? pages[0]?.slug ?? \"\"\n  )\n  const [query, setQuery] = React.useState(\"\")\n  const [sidebarCollapsed, setSidebarCollapsed] = React.useState(false)\n  const [activeHeadingId, setActiveHeadingId] = React.useState<string>()\n  const [containerWidth, setContainerWidth] = React.useState(0)\n  const rootRef = React.useRef<HTMLDivElement | null>(null)\n  const mainRef = React.useRef<HTMLElement | null>(null)\n  const searchRef = React.useRef<HTMLInputElement | null>(null)\n\n  const currentSlug = activeSlug ?? internalSlug\n  const activePage = pages.find((page) => page.slug === currentSlug) ?? pages[0]\n  const activeIndex = activePage\n    ? pages.findIndex((page) => page.slug === activePage.slug)\n    : -1\n  const previousPage = activeIndex > 0 ? pages[activeIndex - 1] : null\n  const nextPage =\n    activeIndex >= 0 && activeIndex < pages.length - 1\n      ? pages[activeIndex + 1]\n      : null\n  const headings = React.useMemo(\n    () => extractHeadings(activePage?.markdown ?? \"\"),\n    [activePage?.markdown]\n  )\n  const filteredPages = React.useMemo(\n    () => pages.filter((page) => matchesQuery(page, query)),\n    [pages, query]\n  )\n  const groupedPages = React.useMemo(\n    () => groupPages(filteredPages),\n    [filteredPages]\n  )\n  const [copiedPage, setCopiedPage] = useCopiedLabel()\n  const [copiedLink, setCopiedLink] = useCopiedLabel()\n  const measuredWidth =\n    containerWidth || (typeof window === \"undefined\" ? 1360 : window.innerWidth)\n  const isCompactLayout = measuredWidth < 768\n  const showSidebar = !isCompactLayout\n  const showDesktopContents = measuredWidth >= 1120\n  const showInlineContents = !showDesktopContents\n\n  React.useLayoutEffect(() => {\n    const root = rootRef.current\n    if (!root) return\n\n    function measure() {\n      const currentRoot = rootRef.current\n      if (!currentRoot) return\n      setContainerWidth(currentRoot.getBoundingClientRect().width)\n    }\n\n    measure()\n    const observer = new ResizeObserver(measure)\n    observer.observe(root)\n    window.addEventListener(\"resize\", measure)\n\n    return () => {\n      observer.disconnect()\n      window.removeEventListener(\"resize\", measure)\n    }\n  }, [])\n\n  React.useEffect(() => {\n    const query = window.matchMedia(\"(max-width: 767px)\")\n    setSidebarCollapsed(query.matches)\n\n    function handleChange(event: MediaQueryListEvent) {\n      if (event.matches) setSidebarCollapsed(true)\n    }\n\n    query.addEventListener(\"change\", handleChange)\n    return () => query.removeEventListener(\"change\", handleChange)\n  }, [])\n\n  const getHeadingElement = React.useCallback((id: string) => {\n    const root = rootRef.current\n    const element = document.getElementById(id)\n    if (element && (!root || root.contains(element))) return element\n    return null\n  }, [])\n\n  const scrollToHeading = React.useCallback(\n    (id: string) => {\n      const element = getHeadingElement(id)\n      if (!element) return\n\n      const reduceMotion = window.matchMedia(\n        \"(prefers-reduced-motion: reduce)\"\n      ).matches\n      const behavior: ScrollBehavior = reduceMotion ? \"auto\" : \"smooth\"\n      const scroller = mainRef.current\n      const hasPanelScroll =\n        scroller && scroller.scrollHeight > scroller.clientHeight + 1\n\n      if (scroller && hasPanelScroll) {\n        const scrollerBounds = scroller.getBoundingClientRect()\n        const elementBounds = element.getBoundingClientRect()\n        const top =\n          elementBounds.top - scrollerBounds.top + scroller.scrollTop - 24\n        scroller.scrollTo({ top, behavior })\n        return\n      }\n\n      element.scrollIntoView({ behavior, block: \"start\" })\n    },\n    [getHeadingElement]\n  )\n\n  const navigate = React.useCallback(\n    (slug: string, hash?: string) => {\n      onNavigate?.(slug, hash)\n      if (!activeSlug) setInternalSlug(slug)\n\n      if (hash) {\n        window.requestAnimationFrame(() => scrollToHeading(hash))\n      }\n    },\n    [activeSlug, onNavigate, scrollToHeading]\n  )\n\n  React.useEffect(() => {\n    function handleKeyDown(event: KeyboardEvent) {\n      if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === \"k\") {\n        event.preventDefault()\n        searchRef.current?.focus()\n        searchRef.current?.select()\n      }\n      if (\n        event.key === \"Escape\" &&\n        document.activeElement === searchRef.current\n      ) {\n        setQuery(\"\")\n      }\n    }\n\n    window.addEventListener(\"keydown\", handleKeyDown)\n    return () => window.removeEventListener(\"keydown\", handleKeyDown)\n  }, [])\n\n  React.useEffect(() => {\n    if (headings.length === 0) return\n\n    function syncActiveHeading() {\n      const scroller = mainRef.current\n      const hasPanelScroll =\n        scroller && scroller.scrollHeight > scroller.clientHeight + 1\n      const threshold = hasPanelScroll\n        ? scroller.getBoundingClientRect().top + 80\n        : headerOffset + 80\n      let next = headings[0]?.id\n\n      for (const heading of headings) {\n        const element = getHeadingElement(heading.id)\n        if (!element) continue\n        if (element.getBoundingClientRect().top <= threshold) {\n          next = heading.id\n        }\n      }\n\n      setActiveHeadingId((current) => (current === next ? current : next))\n    }\n\n    syncActiveHeading()\n    const scroller = mainRef.current\n    scroller?.addEventListener(\"scroll\", syncActiveHeading, { passive: true })\n    window.addEventListener(\"scroll\", syncActiveHeading, { passive: true })\n    window.addEventListener(\"resize\", syncActiveHeading)\n\n    return () => {\n      scroller?.removeEventListener(\"scroll\", syncActiveHeading)\n      window.removeEventListener(\"scroll\", syncActiveHeading)\n      window.removeEventListener(\"resize\", syncActiveHeading)\n    }\n  }, [getHeadingElement, headings, headerOffset])\n\n  async function copyPage() {\n    if (!activePage) return\n    try {\n      await navigator.clipboard.writeText(activePage.markdown)\n      setCopiedPage(true)\n      toast.success(\"Copied page markdown\")\n    } catch {\n      toast.error(\"Could not copy page\")\n    }\n  }\n\n  async function copyPageLink() {\n    if (!activePage) return\n    const path = getPagePath(basePath, activePage.slug, activeHeadingId)\n    const href =\n      typeof window === \"undefined\"\n        ? path\n        : new URL(path, window.location.origin).toString()\n\n    try {\n      await navigator.clipboard.writeText(href)\n      setCopiedLink(true)\n      toast.success(\"Copied page link\")\n    } catch {\n      toast.error(\"Could not copy page link\")\n    }\n  }\n\n  function downloadMarkdown() {\n    if (!activePage) return\n    const blob = new Blob([activePage.markdown], { type: \"text/markdown\" })\n    const url = URL.createObjectURL(blob)\n    const anchor = document.createElement(\"a\")\n    anchor.href = url\n    anchor.download = `${activePage.slug}.md`\n    anchor.click()\n    URL.revokeObjectURL(url)\n  }\n\n  if (!activePage) {\n    return (\n      <div\n        className={cn(\n          \"rounded-md border border-dashed p-10 text-center\",\n          className\n        )}\n      >\n        <FileTextIcon className=\"mx-auto size-8 text-muted-foreground\" />\n        <h2 className=\"mt-4 text-lg font-semibold\">No resources found</h2>\n        <p className=\"mt-2 text-sm text-muted-foreground\">\n          Pass at least one page to render the wiki.\n        </p>\n      </div>\n    )\n  }\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\n        \"mx-auto flex min-h-0 w-full max-w-[1360px] flex-col\",\n        className\n      )}\n      style={\n        {\n          \"--resource-header-offset\": `${headerOffset}px`,\n        } as React.CSSProperties\n      }\n    >\n      <div\n        className={cn(\"grid min-h-0 flex-1 gap-6 px-2 xl:gap-8 xl:pr-4\")}\n        style={{\n          gridTemplateColumns: showSidebar\n            ? showDesktopContents\n              ? sidebarCollapsed\n                ? \"40px minmax(0, 1fr) 180px\"\n                : \"200px minmax(0, 1fr) 180px\"\n              : sidebarCollapsed\n                ? \"40px minmax(0, 1fr)\"\n                : \"200px minmax(0, 1fr)\"\n            : \"minmax(0, 1fr)\",\n        }}\n      >\n        {showSidebar ? (\n          <aside className=\"min-w-0 md:sticky md:top-[calc(var(--resource-header-offset)+1rem)] md:max-h-[calc(100svh-var(--resource-header-offset)-2rem)] md:overflow-hidden\">\n            <div\n              className={cn(\n                \"flex items-center gap-2\",\n                sidebarCollapsed && \"justify-center\"\n              )}\n            >\n              {!sidebarCollapsed ? (\n                <>\n                  <span className=\"min-w-0 truncate text-sm font-medium\">\n                    {label}\n                  </span>\n                  {badge ? (\n                    <Badge variant=\"outline\" className=\"ml-auto rounded-md\">\n                      {badge}\n                    </Badge>\n                  ) : null}\n                </>\n              ) : null}\n              <Button\n                type=\"button\"\n                size=\"icon-sm\"\n                variant=\"outline\"\n                className={cn(!sidebarCollapsed && \"ml-auto\")}\n                onClick={() => setSidebarCollapsed((collapsed) => !collapsed)}\n                aria-label={\n                  sidebarCollapsed\n                    ? \"Expand resource navigation\"\n                    : \"Collapse resource navigation\"\n                }\n                aria-expanded={!sidebarCollapsed}\n              >\n                {sidebarCollapsed ? (\n                  <PanelLeftOpenIcon className=\"size-4\" />\n                ) : (\n                  <PanelLeftCloseIcon className=\"size-4\" />\n                )}\n              </Button>\n            </div>\n\n            {!sidebarCollapsed ? (\n              <>\n                <div className=\"relative mt-4\">\n                  <SearchIcon className=\"pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground\" />\n                  <Input\n                    ref={searchRef}\n                    value={query}\n                    onChange={(event) => setQuery(event.target.value)}\n                    placeholder=\"Search resources...\"\n                    className=\"pl-8\"\n                  />\n                </div>\n                <div\n                  className=\"mt-4 text-xs text-muted-foreground\"\n                  aria-live=\"polite\"\n                >\n                  {filteredPages.length}{\" \"}\n                  {filteredPages.length === 1 ? \"result\" : \"results\"}\n                </div>\n                <ScrollArea className=\"mt-4 max-h-[220px] pr-3 md:max-h-[calc(100svh-var(--resource-header-offset)-11rem)]\">\n                  <div className=\"grid gap-5 pb-6\">\n                    {Object.entries(groupedPages).map(([group, groupPages]) => (\n                      <div key={group}>\n                        <div className=\"mb-1 px-2 text-[11px] font-medium tracking-wide text-muted-foreground uppercase\">\n                          {group}\n                        </div>\n                        <div className=\"grid gap-1\">\n                          {groupPages.map((page) => {\n                            const active = page.slug === activePage.slug\n                            return (\n                              <a\n                                key={page.slug}\n                                href={getPagePath(basePath, page.slug)}\n                                className={cn(\n                                  \"relative rounded-md px-2 py-2 text-xs leading-snug text-muted-foreground transition-colors hover:bg-muted/70 hover:text-foreground\",\n                                  active &&\n                                    \"bg-muted font-medium text-foreground\"\n                                )}\n                                onClick={(event) => {\n                                  event.preventDefault()\n                                  navigate(page.slug)\n                                }}\n                              >\n                                {active ? (\n                                  <span className=\"absolute top-1/2 left-0 size-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-foreground\" />\n                                ) : null}\n                                {page.title}\n                              </a>\n                            )\n                          })}\n                        </div>\n                      </div>\n                    ))}\n                    {filteredPages.length === 0 ? (\n                      <div className=\"rounded-md border border-dashed p-4 text-center text-sm text-muted-foreground\">\n                        No matching resources.\n                      </div>\n                    ) : null}\n                  </div>\n                </ScrollArea>\n              </>\n            ) : null}\n          </aside>\n        ) : null}\n\n        <main ref={mainRef} className=\"min-h-0 min-w-0 overflow-y-auto pb-16\">\n          <div className=\"flex flex-wrap items-center gap-2 pt-2 md:pt-10\">\n            <div className=\"mr-auto flex min-w-0 items-center gap-2 text-xs text-muted-foreground\">\n              <span>{label}</span>\n              <ChevronRightIcon className=\"size-3.5\" />\n              <span className=\"truncate\">{activePage.group}</span>\n            </div>\n            <ResourceActionButton copied={copiedPage} onClick={copyPage}>\n              {!copiedPage ? <CopyIcon className=\"size-4\" /> : null}\n              {copiedPage ? \"Copied\" : \"Copy page\"}\n            </ResourceActionButton>\n            <DropdownMenu>\n              <DropdownMenuTrigger asChild>\n                <Button\n                  size=\"icon-sm\"\n                  variant=\"outline\"\n                  aria-label=\"Resource actions\"\n                >\n                  <MoreHorizontalIcon className=\"size-4\" />\n                </Button>\n              </DropdownMenuTrigger>\n              <DropdownMenuContent align=\"end\">\n                <DropdownMenuItem onClick={copyPageLink}>\n                  {copiedLink ? (\n                    <CheckIcon className=\"size-4\" />\n                  ) : (\n                    <LinkIcon className=\"size-4\" />\n                  )}\n                  {copiedLink ? \"Copied link\" : \"Copy page link\"}\n                </DropdownMenuItem>\n                <DropdownMenuItem onClick={downloadMarkdown}>\n                  <DownloadIcon className=\"size-4\" />\n                  Download Markdown\n                </DropdownMenuItem>\n              </DropdownMenuContent>\n            </DropdownMenu>\n            <Button\n              size=\"icon-sm\"\n              variant=\"outline\"\n              disabled={!previousPage}\n              onClick={() => previousPage && navigate(previousPage.slug)}\n              aria-label=\"Previous resource\"\n            >\n              <ChevronLeftIcon className=\"size-4\" />\n            </Button>\n            <Button\n              size=\"icon-sm\"\n              variant=\"outline\"\n              disabled={!nextPage}\n              onClick={() => nextPage && navigate(nextPage.slug)}\n              aria-label=\"Next resource\"\n            >\n              <ChevronRightIcon className=\"size-4\" />\n            </Button>\n          </div>\n\n          <div className=\"max-w-3xl pt-6\">\n            <h1 className=\"text-4xl font-semibold tracking-tight md:text-[2.625rem]\">\n              {activePage.title}\n            </h1>\n            <p className=\"mt-3 text-lg text-muted-foreground\">\n              {activePage.description}\n            </p>\n            {activePage.readTime || activePage.updatedAt ? (\n              <div className=\"mt-4 flex flex-wrap gap-2 text-xs text-muted-foreground\">\n                {activePage.readTime ? (\n                  <Badge variant=\"secondary\">{activePage.readTime}</Badge>\n                ) : null}\n                {activePage.updatedAt ? (\n                  <Badge variant=\"outline\">\n                    Updated {activePage.updatedAt}\n                  </Badge>\n                ) : null}\n              </div>\n            ) : null}\n          </div>\n\n          {showInlineContents ? (\n            <div className=\"mt-8 rounded-md border p-4\">\n              <TableOfContents\n                headings={headings}\n                activeId={activeHeadingId}\n                onHeadingClick={(id) => {\n                  setActiveHeadingId(id)\n                  scrollToHeading(id)\n                }}\n              />\n            </div>\n          ) : null}\n\n          <article className=\"mt-8 max-w-3xl min-w-0 space-y-4\">\n            <ResourceMarkdown\n              markdown={activePage.markdown}\n              onNavigate={navigate}\n            />\n          </article>\n\n          <Separator className=\"my-10\" />\n          <div className=\"grid gap-3 sm:grid-cols-2\">\n            <ResourcePageNav\n              page={previousPage}\n              label=\"Previous\"\n              basePath={basePath}\n              onNavigate={navigate}\n            />\n            <ResourcePageNav\n              page={nextPage}\n              label=\"Next\"\n              basePath={basePath}\n              onNavigate={navigate}\n              align=\"end\"\n            />\n          </div>\n        </main>\n\n        {showDesktopContents ? (\n          <aside>\n            <div className=\"sticky top-[calc(var(--resource-header-offset)+3rem)] max-h-[calc(100svh-var(--resource-header-offset)-4rem)] overflow-hidden\">\n              <TableOfContents\n                headings={headings}\n                activeId={activeHeadingId}\n                onHeadingClick={(id) => {\n                  setActiveHeadingId(id)\n                  scrollToHeading(id)\n                }}\n              />\n            </div>\n          </aside>\n        ) : null}\n      </div>\n    </div>\n  )\n}\n\nfunction ResourcePageNav({\n  page,\n  label,\n  basePath,\n  onNavigate,\n  align,\n}: {\n  page: ResourcePage | null\n  label: string\n  basePath: string\n  onNavigate: (slug: string) => void\n  align?: \"end\"\n}) {\n  const content = (\n    <>\n      <span className=\"block text-xs text-muted-foreground\">{label}</span>\n      <span className=\"mt-1 block font-medium\">{page?.title ?? \"None\"}</span>\n    </>\n  )\n\n  if (!page) {\n    return (\n      <div\n        aria-disabled=\"true\"\n        className={cn(\n          \"rounded-md border p-3 text-sm opacity-50\",\n          align === \"end\" && \"text-right\"\n        )}\n      >\n        {content}\n      </div>\n    )\n  }\n\n  return (\n    <a\n      href={getPagePath(basePath, page.slug)}\n      className={cn(\n        \"rounded-md border p-3 text-sm transition-colors hover:bg-muted/50\",\n        align === \"end\" && \"text-right\"\n      )}\n      onClick={(event: React.MouseEvent) => {\n        event.preventDefault()\n        onNavigate(page.slug)\n      }}\n    >\n      {content}\n    </a>\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}