{
  "name": "message-scroller",
  "type": "registry:ui",
  "description": "message-scroller component for the Canadian AI design system",
  "files": [
    {
      "path": "components/ui/message-scroller.tsx",
      "content": "\"use client\"\n\n// Canadian AI adaptation of shadcn/ui AI Elements (Base Chat / Message Scroller).\n// Canonical source: https://ui.shadcn.com/docs/ai-elements/base/chat\nimport * as React from \"react\"\nimport { ArrowDown } from \"lucide-react\"\n\ntype ContextValue = {\n  viewportRef: React.RefObject<HTMLDivElement | null>\n  atBottom: boolean\n  setAtBottom: React.Dispatch<React.SetStateAction<boolean>>\n  scrollToBottom: () => void\n  autoScroll: boolean\n}\nconst ScrollerContext = React.createContext<ContextValue | null>(null)\n\nfunction useScroller() {\n  const value = React.useContext(ScrollerContext)\n  if (!value) throw new Error(\"MessageScroller must be nested in MessageScrollerProvider\")\n  return value\n}\n\nexport function MessageScrollerProvider({ children, autoScroll = false }: { children: React.ReactNode; autoScroll?: boolean }) {\n  const viewportRef = React.useRef<HTMLDivElement>(null)\n  const [atBottom, setAtBottom] = React.useState(true)\n  const scrollToBottom = React.useCallback(() => {\n    const viewport = viewportRef.current\n    if (viewport) viewport.scrollTop = viewport.scrollHeight\n    setAtBottom(true)\n  }, [])\n  return (\n    <ScrollerContext.Provider value={{ viewportRef, atBottom, setAtBottom, scrollToBottom, autoScroll }}>\n      {children}\n    </ScrollerContext.Provider>\n  )\n}\n\nexport function MessageScroller({ children, className = \"\" }: { children: React.ReactNode; className?: string }) {\n  return <div className={`relative flex min-h-0 flex-1 flex-col ${className}`}>{children}</div>\n}\n\nexport function MessageScrollerViewport({ children, className = \"\" }: { children: React.ReactNode; className?: string }) {\n  const { viewportRef, atBottom, setAtBottom, autoScroll } = useScroller()\n  React.useEffect(() => {\n    const viewport = viewportRef.current\n    if (!viewport || !autoScroll) return\n    const observer = new ResizeObserver(() => {\n      if (atBottom) viewport.scrollTop = viewport.scrollHeight\n    })\n    const content = viewport.firstElementChild\n    if (content) observer.observe(content)\n    return () => observer.disconnect()\n  }, [viewportRef, atBottom, autoScroll])\n  return (\n    <div ref={viewportRef} onScroll={(event) => {\n      const target = event.currentTarget\n      setAtBottom(target.scrollHeight - target.scrollTop - target.clientHeight < 48)\n    }} className={`min-h-0 flex-1 overflow-y-auto overscroll-contain ${className}`}>\n      {children}\n    </div>\n  )\n}\n\nexport function MessageScrollerContent({ children, className = \"\" }: { children: React.ReactNode; className?: string }) {\n  return <div className={className}>{children}</div>\n}\n\nexport function MessageScrollerItem({ children, messageId, scrollAnchor = false, className = \"\" }: {\n  children: React.ReactNode\n  messageId: string\n  scrollAnchor?: boolean\n  className?: string\n}) {\n  const { viewportRef, scrollToBottom, autoScroll } = useScroller()\n  const previous = React.useRef<string | null>(null)\n  React.useEffect(() => {\n    if (!scrollAnchor || !autoScroll || previous.current === messageId) return\n    previous.current = messageId\n    // The user's new turn advances the conversation to the live edge.\n    scrollToBottom()\n  }, [messageId, scrollAnchor, scrollToBottom, autoScroll, viewportRef])\n  return <div data-message-id={messageId} className={className}>{children}</div>\n}\n\nexport function MessageScrollerButton({ className = \"\" }: { className?: string }) {\n  const { atBottom, scrollToBottom } = useScroller()\n  if (atBottom) return null\n  return (\n    <button type=\"button\" aria-label=\"Jump to latest message\" onClick={scrollToBottom}\n      className={`absolute bottom-3 left-1/2 z-10 -translate-x-1/2 rounded-full border border-border bg-background p-2 text-foreground shadow-sm hover:bg-secondary ${className}`}>\n      <ArrowDown className=\"size-4\" />\n    </button>\n  )\n}\n",
      "type": "registry:ui"
    }
  ]
}