{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-nav-dots",
  "title": "Nav Dots",
  "description": "Dot-based section navigation with automatic scroll tracking and tooltips.",
  "dependencies": [
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@lema-ds/tooltip",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider"
  ],
  "files": [
    {
      "path": "components/ds/ds-nav-dots.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\n\nimport { cn } from \"@/lib/utils\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipProvider,\n  TooltipTrigger,\n} from \"@/components/ui/tooltip\"\n\n// ── Types ──────────────────────────────────────────────────────────────────\n\nexport type NavDotsContainerVariantProps = VariantProps<\n  typeof navDotsContainerVariants\n>\nexport type NavDotsDotVariantProps = VariantProps<typeof navDotsDotVariants>\nexport type NavDotsPosition = \"left\" | \"right\"\nexport type NavDotsOrientation = \"vertical\" | \"horizontal\"\n\n/** A section entry for dot navigation. */\nexport interface NavDotsSection {\n  /** Element ID used for scroll targeting */\n  id: string\n  /** Label shown in the tooltip */\n  label: string\n}\n\n/**\n * NavDots — dot-based section navigation with scroll tracking and tooltips.\n *\n * Automatically detects which section is in view via `IntersectionObserver`\n * and highlights the corresponding dot. Clicking a dot smooth-scrolls to\n * that section. Supports vertical (side rail) and horizontal (bottom bar)\n * orientations.\n *\n * Uses the shadcn `Tooltip` primitive for accessible, animated labels.\n */\nexport interface NavDotsProps\n  extends NavDotsContainerVariantProps, React.HTMLAttributes<HTMLDivElement> {\n  /** Array of sections to navigate between */\n  sections: NavDotsSection[]\n  /** Initially active section index */\n  active?: number\n  /** Enable smooth scroll when clicking a dot */\n  scrollOnClick?: boolean\n  /**\n   * Scroll container to observe. Defaults to `null` which means the\n   * component will walk up the DOM to find the nearest scrollable ancestor.\n   * Pass a ref or `\"window\"` to override.\n   */\n  scrollContainer?: React.RefObject<HTMLElement | null> | \"window\" | null\n  /** IntersectionObserver rootMargin (default: \"0px\") */\n  scrollMargin?: string\n  /** Callback when the active section changes */\n  onActiveChange?: (index: number) => void\n  locale?: UILocale\n}\n\n// ── Variants ───────────────────────────────────────────────────────────────\n\nexport const navDotsContainerVariants = cva(\n  [\"fixed z-50 flex gap-2 transition-opacity duration-200 ease-in-out\"],\n  {\n    variants: {\n      position: {\n        left: [],\n        right: [],\n      },\n      orientation: {\n        vertical: [\"flex-col\"],\n        horizontal: [\"flex-row\"],\n      },\n      visible: {\n        true: [\"opacity-100\"],\n        false: [\"pointer-events-none opacity-0\"],\n      },\n    },\n    compoundVariants: [\n      // Vertical: pin to left/right edge, centered vertically\n      {\n        orientation: \"vertical\",\n        position: \"left\",\n        className: \"top-1/2 left-4 -translate-y-1/2\",\n      },\n      {\n        orientation: \"vertical\",\n        position: \"right\",\n        className: \"top-1/2 right-4 -translate-y-1/2\",\n      },\n      // Horizontal: pin to top, centered horizontally\n      {\n        orientation: \"horizontal\",\n        position: \"left\",\n        className: \"top-4 left-1/2 -translate-x-1/2\",\n      },\n      {\n        orientation: \"horizontal\",\n        position: \"right\",\n        className: \"top-4 left-1/2 -translate-x-1/2\",\n      },\n    ],\n    defaultVariants: {\n      position: \"right\",\n      orientation: \"vertical\",\n      visible: true,\n    },\n  }\n)\n\nexport const navDotsDotVariants = cva(\n  [\n    \"relative size-2 rounded-full\",\n    \"transition-all duration-200 ease-in-out\",\n    \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-none\",\n  ],\n  {\n    variants: {\n      active: {\n        true: [\"bg-foreground\", \"scale-125\"],\n        false: [\"bg-border\", \"hover:bg-foreground\", \"hover:scale-125\"],\n      },\n      interactive: {\n        true: [\"cursor-pointer\"],\n        false: [\"cursor-default\"],\n      },\n    },\n    defaultVariants: {\n      active: false,\n      interactive: true,\n    },\n  }\n)\n\n// ── Helpers ────────────────────────────────────────────────────────────────\n\n/** Walk up the DOM tree to find the nearest scrollable ancestor. */\nfunction findScrollParent(el: HTMLElement | null): HTMLElement | null {\n  if (!el) return null\n  let current = el.parentElement\n  while (current) {\n    const { overflow, overflowY } = getComputedStyle(current)\n    if (/(auto|scroll)/.test(overflow + overflowY)) return current\n    current = current.parentElement\n  }\n  return null\n}\n\n// ── Component ──────────────────────────────────────────────────────────────\n\nexport const NavDots = React.forwardRef<HTMLDivElement, NavDotsProps>(\n  (\n    {\n      sections,\n      active = 0,\n      scrollOnClick = true,\n      scrollContainer = null,\n      scrollMargin = \"0px\",\n      onActiveChange,\n      orientation,\n      position,\n      locale: localeProp,\n      className,\n      ...props\n    },\n    ref\n  ) => {\n    const locale = useUILocale(localeProp)\n    const [currentActive, setCurrentActive] = React.useState(active)\n    const internalRef = React.useRef<HTMLDivElement>(null)\n\n    // Resolve combined ref\n    React.useImperativeHandle(ref, () => internalRef.current!)\n\n    // Tooltip placement depends on orientation/position\n    const tooltipSide = React.useMemo(() => {\n      if (orientation === \"horizontal\") return \"bottom\" as const\n      return position === \"left\" ? (\"right\" as const) : (\"left\" as const)\n    }, [orientation, position])\n\n    // ── Scroll-to on click ──────────────────────────────────────────────\n\n    const scrollTo = React.useCallback(\n      (id: string) => {\n        if (!scrollOnClick) return\n        const el = document.getElementById(id)\n        if (el) el.scrollIntoView({ behavior: \"smooth\" })\n      },\n      [scrollOnClick]\n    )\n\n    // ── IntersectionObserver for scroll tracking ────────────────────────\n\n    React.useEffect(() => {\n      const elements = sections\n        .map((s) => document.getElementById(s.id))\n        .filter(Boolean) as HTMLElement[]\n\n      if (elements.length === 0) return\n\n      // Determine the observation root\n      let root: HTMLElement | null = null\n      if (scrollContainer === \"window\") {\n        root = null // null = viewport\n      } else if (scrollContainer && \"current\" in scrollContainer) {\n        root = scrollContainer.current\n      } else {\n        root = findScrollParent(internalRef.current)\n      }\n\n      const ratios = new Map<string, number>()\n\n      const observer = new IntersectionObserver(\n        (entries) => {\n          for (const entry of entries) {\n            ratios.set(entry.target.id, entry.intersectionRatio)\n          }\n\n          // Pick the section with the highest intersection ratio\n          let bestIndex = 0\n          let bestRatio = -1\n          for (let i = 0; i < sections.length; i++) {\n            const ratio = ratios.get(sections[i].id) ?? 0\n            if (ratio > bestRatio) {\n              bestRatio = ratio\n              bestIndex = i\n            }\n          }\n\n          setCurrentActive((prev) => {\n            if (prev !== bestIndex) {\n              onActiveChange?.(bestIndex)\n              return bestIndex\n            }\n            return prev\n          })\n        },\n        {\n          root,\n          rootMargin: scrollMargin,\n          threshold: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1],\n        }\n      )\n\n      for (const el of elements) observer.observe(el)\n      return () => observer.disconnect()\n    }, [sections, scrollContainer, scrollMargin, onActiveChange])\n\n    return (\n      <TooltipProvider>\n        <div\n          ref={internalRef}\n          data-slot=\"nav-dots\"\n          role=\"navigation\"\n          aria-label={UI_I18N[locale].navDots.sectionNav}\n          className={cn(\n            navDotsContainerVariants({\n              orientation,\n              position,\n              visible: true,\n            }),\n            className\n          )}\n          {...props}\n        >\n          {sections.map((s, i) => (\n            <Tooltip key={s.id}>\n              <TooltipTrigger asChild>\n                <button\n                  data-slot=\"nav-dots-dot\"\n                  type=\"button\"\n                  onClick={() => {\n                    setCurrentActive(i)\n                    scrollTo(s.id)\n                  }}\n                  aria-label={`${UI_I18N[locale].navDots.goTo}: ${s.label}`}\n                  aria-current={i === currentActive ? \"true\" : undefined}\n                  className={navDotsDotVariants({\n                    active: i === currentActive,\n                    interactive: scrollOnClick,\n                  })}\n                />\n              </TooltipTrigger>\n              <TooltipContent side={tooltipSide} sideOffset={8}>\n                {s.label}\n              </TooltipContent>\n            </Tooltip>\n          ))}\n        </div>\n      </TooltipProvider>\n    )\n  }\n)\n\nNavDots.displayName = \"NavDots\"\n\nexport default NavDots\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
