{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slide-view-tracking",
  "title": "Slide View Tracking",
  "description": "Use this when impressions matter: a looping scale carousel that reports each slide once after it has been selected for a second, only while the tab is visible, and never for a slide that was only scrolled past.",
  "registryDependencies": [
    "@tealmac/carousel-scale"
  ],
  "files": [
    {
      "path": "registry/patterns/slide-view-tracking/slide-view-tracking.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport type { CarouselItem } from \"@/components/ui/carousel-kit\"\nimport { CarouselScale } from \"@/components/ui/carousel-scale\"\n\nexport interface SlideViewTrackingProps {\n  items: CarouselItem[]\n  label: string\n  dwellMs?: number\n  onView?: (id: string, index: number) => void\n  className?: string\n}\n\nexport function SlideViewTracking({\n  items,\n  label,\n  dwellMs = 1000,\n  onView,\n  className,\n}: SlideViewTrackingProps) {\n  const [index, setIndex] = React.useState(0)\n  const [visible, setVisible] = React.useState(true)\n  const seen = React.useRef(new Set<string>())\n  const onViewRef = React.useRef(onView)\n  onViewRef.current = onView\n\n  React.useEffect(() => {\n    const update = () => setVisible(document.visibilityState !== \"hidden\")\n    update()\n    document.addEventListener(\"visibilitychange\", update)\n    return () => document.removeEventListener(\"visibilitychange\", update)\n  }, [])\n\n  React.useEffect(() => {\n    const item = items[index]\n    if (!item || !visible || seen.current.has(item.id)) return\n    const timer = window.setTimeout(() => {\n      seen.current.add(item.id)\n      onViewRef.current?.(item.id, index)\n    }, dwellMs)\n    // Moving on, or hiding the tab, cancels this slide's count.\n    return () => window.clearTimeout(timer)\n  }, [index, visible, items, dwellMs])\n\n  return (\n    <CarouselScale\n      label={label}\n      className={className}\n      onIndexChange={setIndex}\n      items={items}\n    />\n  )\n}\n",
      "type": "registry:block"
    }
  ],
  "type": "registry:block"
}