{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "drag-to-confirm",
  "type": "registry:ui",
  "title": "Drag to Confirm",
  "dependencies": [
    "motion",
    "lucide-react"
  ],
  "files": [
    {
      "path": "components/ui/drag-to-confirm.tsx",
      "content": "\"use client\";\n\nimport React, { useEffect, useRef, useState } from \"react\";\nimport { animate, motion, useMotionValue, useTransform } from \"motion/react\";\nimport { Check, ChevronRight, RotateCcw, Trash2 } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface DragToConfirmProps {\n  label?: string;\n  confirmedLabel?: string;\n  variant?: \"default\" | \"danger\";\n  onConfirm?: () => void;\n  autoResetMs?: number;\n  className?: string;\n}\n\nexport function DragToConfirm({\n  label = \"Slide to deploy production\",\n  confirmedLabel = \"Deployment started\",\n  variant = \"default\",\n  onConfirm,\n  autoResetMs = 2400,\n  className,\n}: DragToConfirmProps) {\n  const trackRef = useRef<HTMLDivElement>(null);\n  const [maxDrag, setMaxDrag] = useState(220);\n  const [confirmed, setConfirmed] = useState(false);\n  const [tone, setTone] = useState<\"default\" | \"danger\">(variant);\n  const x = useMotionValue(0);\n\n  const thumbSize = 40;\n  const padding = 4;\n\n  useEffect(() => {\n    const updateWidth = () => {\n      if (!trackRef.current) return;\n      const w = trackRef.current.clientWidth;\n      setMaxDrag(Math.max(80, w - thumbSize - padding * 2));\n    };\n    updateWidth();\n    window.addEventListener(\"resize\", updateWidth);\n    return () => window.removeEventListener(\"resize\", updateWidth);\n  }, []);\n\n  useEffect(() => {\n    if (!confirmed || !autoResetMs) return;\n    const t = setTimeout(() => {\n      setConfirmed(false);\n      animate(x, 0, { type: \"spring\", stiffness: 360, damping: 28 });\n    }, autoResetMs);\n    return () => clearTimeout(t);\n  }, [confirmed, autoResetMs, x]);\n\n  const fillWidth = useTransform(x, [0, maxDrag], [thumbSize + padding, maxDrag + thumbSize + padding]);\n  const textOpacity = useTransform(x, [0, maxDrag * 0.55], [1, 0]);\n\n  const handleDragEnd = () => {\n    if (confirmed) return;\n    const current = x.get();\n    if (current >= maxDrag * 0.82) {\n      animate(x, maxDrag, { type: \"spring\", stiffness: 420, damping: 30 });\n      setConfirmed(true);\n      onConfirm?.();\n    } else {\n      animate(x, 0, { type: \"spring\", stiffness: 380, damping: 26 });\n    }\n  };\n\n  const reset = () => {\n    setConfirmed(false);\n    animate(x, 0, { type: \"spring\", stiffness: 380, damping: 28 });\n  };\n\n  const isDanger = tone === \"danger\";\n\n  return (\n    <div className={cn(\"w-full max-w-sm space-y-3\", className)}>\n      <div className=\"flex items-center justify-between text-[11px] text-zinc-500\">\n        <span>{isDanger ? \"Destructive action\" : \"High-stakes action\"}</span>\n        <div className=\"inline-flex rounded-full border border-white/10 bg-zinc-900 p-0.5\">\n          {([\"default\", \"danger\"] as const).map((t) => (\n            <button\n              key={t}\n              type=\"button\"\n              onClick={() => {\n                setTone(t);\n                reset();\n              }}\n              className={cn(\n                \"rounded-full px-2 py-0.5 text-[10px] capitalize cursor-pointer transition-colors\",\n                tone === t ? \"bg-white/12 text-white\" : \"text-zinc-500 hover:text-zinc-300\"\n              )}\n            >\n              {t}\n            </button>\n          ))}\n        </div>\n      </div>\n\n      <div\n        ref={trackRef}\n        className={cn(\n          \"relative flex h-12 w-full items-center overflow-hidden rounded-full border p-1 select-none transition-colors\",\n          confirmed\n            ? isDanger\n              ? \"border-rose-500/40 bg-rose-950/40\"\n              : \"border-emerald-500/40 bg-emerald-950/40\"\n            : \"border-white/10 bg-[#101013]\"\n        )}\n      >\n        {/* Progress Fill */}\n        <motion.div\n          style={{ width: fillWidth }}\n          className={cn(\n            \"pointer-events-none absolute inset-y-1 left-1 rounded-full transition-colors\",\n            confirmed\n              ? isDanger\n                ? \"bg-rose-500/25\"\n                : \"bg-emerald-500/25\"\n              : isDanger\n                ? \"bg-rose-500/15\"\n                : \"bg-blue-500/15\"\n          )}\n        />\n\n        {/* Track Label */}\n        <motion.span\n          style={{ opacity: confirmed ? 1 : textOpacity }}\n          className={cn(\n            \"pointer-events-none absolute inset-0 flex items-center justify-center text-xs font-medium tracking-tight\",\n            confirmed\n              ? isDanger\n                ? \"text-rose-300\"\n                : \"text-emerald-300\"\n              : \"text-zinc-400\"\n          )}\n        >\n          {confirmed\n            ? isDanger\n              ? \"Cluster deleted\"\n              : confirmedLabel\n            : isDanger\n              ? \"Slide to delete cluster\"\n              : label}\n        </motion.span>\n\n        {/* Draggable Thumb */}\n        <motion.div\n          drag={confirmed ? false : \"x\"}\n          dragConstraints={{ left: 0, right: maxDrag }}\n          dragElastic={0.04}\n          dragMomentum={false}\n          style={{ x }}\n          onDragEnd={handleDragEnd}\n          whileTap={{ scale: 0.96 }}\n          className={cn(\n            \"relative z-10 flex h-10 w-10 shrink-0 items-center justify-center rounded-full shadow-md transition-colors\",\n            confirmed\n              ? isDanger\n                ? \"bg-rose-500 text-white cursor-default\"\n                : \"bg-emerald-500 text-zinc-950 cursor-default\"\n              : isDanger\n                ? \"bg-rose-500 text-white cursor-grab active:cursor-grabbing\"\n                : \"bg-zinc-100 text-zinc-950 cursor-grab active:cursor-grabbing\"\n          )}\n        >\n          {confirmed ? (\n            <Check className=\"h-4 w-4\" />\n          ) : isDanger ? (\n            <Trash2 className=\"h-4 w-4\" />\n          ) : (\n            <ChevronRight className=\"h-4 w-4\" />\n          )}\n        </motion.div>\n      </div>\n\n      {confirmed && (\n        <div className=\"flex justify-end\">\n          <button\n            type=\"button\"\n            onClick={reset}\n            className=\"inline-flex items-center gap-1 text-[11px] text-zinc-400 hover:text-zinc-200 cursor-pointer\"\n          >\n            <RotateCcw className=\"h-3 w-3\" />\n            Reset\n          </button>\n        </div>\n      )}\n    </div>\n  );\n}\n\n",
      "type": "registry:ui"
    }
  ]
}