{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "swipe-review",
  "title": "Swipe Review",
  "description": "A card queue for grading model answers. Drag right to accept, left to reject.",
  "dependencies": [
    "animejs"
  ],
  "registryDependencies": [
    "https://spotcheckui.com/r/spotcheck-base.json",
    "https://spotcheckui.com/r/button.json",
    "https://spotcheckui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/spotcheck/components/spotcheck/swipe-review.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { animate, spring, utils } from \"animejs\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Button } from \"@/registry/spotcheck/components/spotcheck/button\"\nimport { useReducedMotion } from \"@/registry/spotcheck/hooks/use-reduced-motion\"\n\nconst THRESHOLD_PX = 110\nconst VISIBLE_CARDS = 3\nconst FLING_DISTANCE = 640\nconst FLING_ROTATION = 28\nconst FLING_MS = 420\nconst DRAG_ROTATION = 18\nconst RETURN_SPRING = { stiffness: 220, damping: 11 }\n\nexport type ReviewItem = { id: string; question: string; answer: string; meta: string }\n\n/** Past the threshold a card flies off that way. Otherwise it returns. */\nexport function swipeOutcome(distance: number, threshold: number) {\n  if (Math.abs(distance) <= threshold) return null\n  return distance > 0 ? \"accept\" : \"reject\"\n}\n\ntype SwipeReviewProps = {\n  items: ReviewItem[]\n  /** How far to drag before a card is decided, in pixels. */\n  threshold?: number\n  onAccept?: (item: ReviewItem) => void\n  onReject?: (item: ReviewItem) => void\n  className?: string\n}\n\nexport function SwipeReview({ items, threshold = THRESHOLD_PX, onAccept, onReject, className }: SwipeReviewProps) {\n  const reduced = useReducedMotion()\n  const [position, setPosition] = React.useState(0)\n  const [tally, setTally] = React.useState({ accepted: 0, rejected: 0 })\n  const [distance, setDistance] = React.useState(0)\n  const [flying, setFlying] = React.useState(false)\n  const card = React.useRef<HTMLDivElement>(null)\n  const dragStart = React.useRef<number | null>(null)\n\n  const queue = items.slice(position, position + VISIBLE_CARDS)\n  const current = queue[0]\n\n  const settle = (outcome: \"accept\" | \"reject\") => {\n    if (!current) return\n    if (outcome === \"accept\") onAccept?.(current)\n    else onReject?.(current)\n    setTally((count) =>\n      outcome === \"accept\" ? { ...count, accepted: count.accepted + 1 } : { ...count, rejected: count.rejected + 1 },\n    )\n    setPosition((index) => index + 1)\n    setDistance(0)\n    setFlying(false)\n  }\n\n  const fling = (outcome: \"accept\" | \"reject\") => {\n    if (flying || !card.current) return\n    if (reduced) return settle(outcome)\n    setFlying(true)\n    const direction = outcome === \"accept\" ? 1 : -1\n    animate(card.current, {\n      x: direction * FLING_DISTANCE,\n      rotate: direction * FLING_ROTATION,\n      opacity: 0,\n      duration: FLING_MS,\n      ease: \"inQuad\",\n      onComplete: () => settle(outcome),\n    })\n  }\n\n  const release = (cancelled: boolean) => {\n    if (dragStart.current === null) return\n    dragStart.current = null\n    const outcome = cancelled ? null : swipeOutcome(distance, threshold)\n    if (outcome) return fling(outcome)\n    setDistance(0)\n    if (!card.current) return\n    if (reduced) utils.set(card.current, { x: 0, rotate: 0 })\n    else animate(card.current, { x: 0, rotate: 0, ease: spring(RETURN_SPRING) })\n  }\n\n  return (\n    <div className={cn(\"flex flex-col gap-3.5 font-(family-name:--f-body)\", className)}>\n      <div className=\"relative isolate grid h-75 place-items-center\">\n        {current ? (\n          queue\n            .toReversed()\n            .map((item, reversedIndex, stack) => {\n              const depth = stack.length - 1 - reversedIndex\n              const top = depth === 0\n              return (\n                <div\n                  key={item.id}\n                  ref={top ? card : undefined}\n                  data-testid={top ? \"review-card\" : undefined}\n                  aria-hidden={!top}\n                  className={cn(\n                    \"border-ink bg-raise absolute inset-x-[4%] top-3.5 bottom-6.5 flex flex-col gap-0.5 overflow-hidden border-(length:--rule) px-4 py-3.5 shadow-[6px_6px_0_var(--ink)] select-none md:inset-x-[12%]\",\n                    top && \"cursor-grab touch-pan-y\",\n                  )}\n                  style={top ? undefined : { transform: `translateY(${depth * 10}px) scale(${1 - depth * 0.04})`, zIndex: -depth }}\n                  onPointerDown={\n                    top\n                      ? (event) => {\n                          if (flying) return\n                          event.currentTarget.setPointerCapture(event.pointerId)\n                          dragStart.current = event.clientX\n                        }\n                      : undefined\n                  }\n                  onPointerMove={\n                    top\n                      ? (event) => {\n                          if (dragStart.current === null || !card.current) return\n                          const next = event.clientX - dragStart.current\n                          setDistance(next)\n                          utils.set(card.current, { x: next, rotate: next / DRAG_ROTATION })\n                        }\n                      : undefined\n                  }\n                  onPointerUp={top ? () => release(false) : undefined}\n                  onPointerCancel={top ? () => release(true) : undefined}\n                >\n                  {top && (\n                    <>\n                      <span\n                        aria-hidden\n                        className=\"text-ok absolute top-3 right-3 rotate-6 border-[3px] border-current px-2 py-0.5 font-(family-name:--f-mono) text-sm font-semibold tracking-widest uppercase\"\n                        style={{ opacity: Math.max(0, Math.min(1, distance / threshold)) }}\n                      >\n                        Accept\n                      </span>\n                      <span\n                        aria-hidden\n                        className=\"text-bad absolute top-3 left-3 -rotate-6 border-[3px] border-current px-2 py-0.5 font-(family-name:--f-mono) text-sm font-semibold tracking-widest uppercase\"\n                        style={{ opacity: Math.max(0, Math.min(1, -distance / threshold)) }}\n                      >\n                        Reject\n                      </span>\n                    </>\n                  )}\n                  <div className=\"spotcheck-label\">User asked</div>\n                  <div className=\"spotcheck-heading text-2xl leading-tight text-balance normal-case\">{item.question}</div>\n                  <div className=\"spotcheck-label mt-2.5\">Model answered</div>\n                  <p className=\"mt-0.5 mb-2 max-w-[52ch] text-sm\">{item.answer}</p>\n                  <div className=\"spotcheck-label\">{item.meta}</div>\n                </div>\n              )\n            })\n        ) : (\n          <div className=\"flex flex-col items-center gap-2.5\">\n            <b className=\"spotcheck-display text-[40px]\">Queue clear</b>\n            <span className=\"spotcheck-label\">\n              {tally.accepted} accepted · {tally.rejected} rejected\n            </span>\n          </div>\n        )}\n      </div>\n      <div className=\"flex flex-wrap items-center gap-4\">\n        <Button disabled={!current || flying} onClick={() => fling(\"reject\")}>\n          ← Reject\n        </Button>\n        <Button variant=\"accent\" disabled={!current || flying} onClick={() => fling(\"accept\")}>\n          Accept →\n        </Button>\n        <span role=\"status\" className=\"spotcheck-label\" data-testid=\"review-tally\">\n          {tally.accepted} accepted · {tally.rejected} rejected\n        </span>\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "timelines"
  ],
  "type": "registry:component"
}