{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spin-to-win-wheel",
  "title": "Spin to Win Wheel",
  "description": "A gamified discount-capture widget where visitors spin a weighted SVG prize wheel for a reward, with five glass themes, a themed reveal modal and code copy, rendered inline or as a corner-launched popup with manual/delay/scroll triggers.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/spin-to-win-wheel/spin-to-win-wheel.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ninterface Reward {\n  label: string;\n  code: string;\n}\n\ninterface WheelSegment {\n  label: string;\n  code: string;\n  /** Relative weight for probability (higher = more likely). Default 1. */\n  weight?: number;\n  color?: string;\n}\n\ninterface ThemeConfig {\n  name: string;\n  title: string;\n  subtitle: string;\n  buttonText: string;\n  triggerText: string;\n  glow: string;\n  background: string;\n  segments: WheelSegment[];\n}\n\nconst SEGMENT_PALETTE = [\"#1a1d24\", \"#252a33\", \"#1e222b\", \"#2a303b\", \"#181b21\", \"#222831\", \"#1c2028\", \"#262c36\"];\n\nconst THEMES: { [key: string]: ThemeConfig } = {\n  ecommerce: {\n    name: \"E-Commerce\",\n    title: \"Spin for a Discount\",\n    subtitle: \"3 free spins, real savings\",\n    buttonText: \"Spin Wheel\",\n    triggerText: \"Spin for a Discount\",\n    glow: \"rgba(255,255,255,0.16)\",\n    background: \"linear-gradient(160deg, #07080b 0%, #101319 100%)\",\n    segments: [\n      { label: \"5% off\", code: \"SPIN5\", weight: 3 },\n      { label: \"10% off\", code: \"SPIN10\", weight: 3 },\n      { label: \"15% off\", code: \"SPIN15\", weight: 2 },\n      { label: \"20% off\", code: \"SPIN20\", weight: 2 },\n      { label: \"Free Ship\", code: \"SHIPFREE\", weight: 1 },\n      { label: \"25% off\", code: \"SPIN25\", weight: 1 },\n      { label: \"Try Again\", code: \"SPIN-RETRY\", weight: 2 },\n      { label: \"30% off\", code: \"SPIN30\", weight: 1 },\n    ],\n  },\n  campaign: {\n    name: \"Campaign / Sale\",\n    title: \"Spin Before It's Gone\",\n    subtitle: \"Limited-time drop, spin now\",\n    buttonText: \"Spin for Deal\",\n    triggerText: \"Spin for a Deal\",\n    glow: \"rgba(248,113,113,0.22)\",\n    background: \"linear-gradient(160deg, #0c0505 0%, #1a0808 100%)\",\n    segments: [\n      { label: \"10% off\", code: \"SALE10\", weight: 3 },\n      { label: \"20% off\", code: \"SALE20\", weight: 2 },\n      { label: \"30% off\", code: \"SALE30\", weight: 2 },\n      { label: \"40% off\", code: \"SALE40\", weight: 1 },\n      { label: \"Flash 15%\", code: \"FLASH15\", weight: 2 },\n      { label: \"50% off\", code: \"SALE50\", weight: 1 },\n      { label: \"Try Again\", code: \"SALE-RETRY\", weight: 2 },\n      { label: \"Bundle Deal\", code: \"BUNDLE\", weight: 1 },\n    ],\n  },\n  restaurant: {\n    name: \"Restaurant / Cafe\",\n    title: \"Today's Lucky Spin\",\n    subtitle: \"Scan, spin, treat yourself\",\n    buttonText: \"Spin for Treat\",\n    triggerText: \"Spin for a Treat\",\n    glow: \"rgba(251,191,36,0.20)\",\n    background: \"linear-gradient(160deg, #0c0904 0%, #1a1206 100%)\",\n    segments: [\n      { label: \"Free Coffee\", code: \"CAFE-COFFEE\", weight: 2 },\n      { label: \"10% off\", code: \"CAFE10\", weight: 3 },\n      { label: \"Free Dessert\", code: \"CAFE-DESSERT\", weight: 2 },\n      { label: \"20% off\", code: \"CAFE20\", weight: 2 },\n      { label: \"Appetizer\", code: \"CAFE-APP\", weight: 1 },\n      { label: \"Meal On Us\", code: \"CAFE-FREE\", weight: 1 },\n      { label: \"Try Again\", code: \"CAFE-RETRY\", weight: 2 },\n      { label: \"Free Drink\", code: \"CAFE-DRINK\", weight: 2 },\n    ],\n  },\n  saas: {\n    name: \"SaaS / Freemium\",\n    title: \"Spin for a Plan Discount\",\n    subtitle: \"One spin per new account\",\n    buttonText: \"Spin Wheel\",\n    triggerText: \"Spin for a Discount\",\n    glow: \"rgba(129,140,248,0.22)\",\n    background: \"linear-gradient(160deg, #06050c 0%, #100a1c 100%)\",\n    segments: [\n      { label: \"10% off\", code: \"SAAS10\", weight: 3 },\n      { label: \"20% off\", code: \"SAAS20\", weight: 2 },\n      { label: \"1 Mo Free\", code: \"SAAS-MONTH\", weight: 2 },\n      { label: \"30% off\", code: \"SAAS30\", weight: 2 },\n      { label: \"50% off\", code: \"SAAS50\", weight: 1 },\n      { label: \"3 Mo Free\", code: \"SAAS-3MO\", weight: 1 },\n      { label: \"Try Again\", code: \"SAAS-RETRY\", weight: 2 },\n      { label: \"Pro Upgrade\", code: \"SAAS-PRO\", weight: 1 },\n    ],\n  },\n  event: {\n    name: \"Event / Tickets\",\n    title: \"Spin for an Early Bird Deal\",\n    subtitle: \"Before you check out\",\n    buttonText: \"Spin for Bonus\",\n    triggerText: \"Spin for a Bonus\",\n    glow: \"rgba(45,212,191,0.20)\",\n    background: \"linear-gradient(160deg, #04080a 0%, #081619 100%)\",\n    segments: [\n      { label: \"5% off\", code: \"EVT5\", weight: 3 },\n      { label: \"10% off\", code: \"EVT10\", weight: 3 },\n      { label: \"Drink Ticket\", code: \"EVT-DRINK\", weight: 2 },\n      { label: \"15% off\", code: \"EVT15\", weight: 2 },\n      { label: \"VIP Upgrade\", code: \"EVT-VIP\", weight: 1 },\n      { label: \"Free +1\", code: \"EVT-PLUSONE\", weight: 1 },\n      { label: \"Try Again\", code: \"EVT-RETRY\", weight: 2 },\n      { label: \"Merch Pack\", code: \"EVT-MERCH\", weight: 1 },\n    ],\n  },\n};\n\nfunction GiftIcon() {\n  return (\n    <svg width=\"28\" height=\"28\" viewBox=\"0 0 24 24\" fill=\"none\" aria-hidden=\"true\" focusable=\"false\" className=\"relative\">\n      <rect x=\"3.5\" y=\"10\" width=\"17\" height=\"9.5\" rx=\"1.5\" fill=\"rgba(255,255,255,0.9)\" />\n      <rect x=\"2.5\" y=\"7\" width=\"19\" height=\"4\" rx=\"1\" fill=\"rgba(255,255,255,0.9)\" />\n      <rect x=\"10.4\" y=\"7\" width=\"3.2\" height=\"12.5\" fill=\"rgba(255,255,255,0.9)\" />\n      <path\n        d=\"M12 7c-1.6 0-3-1-3.6-2.1C7.6 3.2 8.5 2 9.8 2c1.3 0 2.2 1.4 2.2 3 0-1.6.9-3 2.2-3 1.3 0 2.2 1.2 1.4 2.9C15 6 13.6 7 12 7z\"\n        fill=\"rgba(255,255,255,0.9)\"\n      />\n    </svg>\n  );\n}\n\n/** Pick a segment index using weighted random. */\nfunction pickWeightedIndex(segments: WheelSegment[]): number {\n  const weights = segments.map((s) => Math.max(0.01, s.weight ?? 1));\n  const total = weights.reduce((a, b) => a + b, 0);\n  let r = Math.random() * total;\n  for (let i = 0; i < weights.length; i++) {\n    r -= weights[i];\n    if (r <= 0) return i;\n  }\n  return segments.length - 1;\n}\n\n/**\n * Wheel segments are drawn with 0° at the TOP (pointer position). Segment i\n * occupies [i * slice, (i+1) * slice) going clockwise. When the wheel rotates\n * by `rotation` CSS degrees (clockwise positive), the segment under the top\n * pointer is index = floor(((360 - (rotation % 360)) % 360) / slice).\n */\nfunction WheelFace({ segments, accentColor, size }: { segments: WheelSegment[]; accentColor: string; size: number }) {\n  const n = segments.length;\n  const slice = 360 / n;\n  const cx = size / 2;\n  const cy = size / 2;\n  const r = size / 2 - 4;\n  const ink = \"#ffffff\";\n  const inkSoft = \"rgba(255,255,255,0.55)\";\n  const stroke = \"rgba(255,255,255,0.1)\";\n\n  const polar = (deg: number, radius: number) => {\n    const rad = ((deg - 90) * Math.PI) / 180;\n    return { x: cx + radius * Math.cos(rad), y: cy + radius * Math.sin(rad) };\n  };\n\n  const wedgePath = (i: number) => {\n    const start = i * slice;\n    const end = (i + 1) * slice;\n    const p1 = polar(start, r);\n    const p2 = polar(end, r);\n    const large = slice > 180 ? 1 : 0;\n    return `M ${cx} ${cy} L ${p1.x} ${p1.y} A ${r} ${r} 0 ${large} 1 ${p2.x} ${p2.y} Z`;\n  };\n\n  return (\n    <svg width={size} height={size} viewBox={`0 0 ${size} ${size}`} className=\"block rounded-full\">\n      <circle cx={cx} cy={cy} r={r + 3} fill=\"#0a0a0f\" stroke={accentColor} strokeWidth={3} opacity={0.95} />\n\n      {segments.map((seg, i) => {\n        const mid = i * slice + slice / 2;\n        const labelPos = polar(mid, r * 0.62);\n        const fill = seg.color || SEGMENT_PALETTE[i % SEGMENT_PALETTE.length];\n        const textAngle = mid > 90 && mid < 270 ? mid + 180 : mid;\n\n        return (\n          <g key={i}>\n            <path d={wedgePath(i)} fill={fill} stroke={stroke} strokeWidth={1} />\n            <text\n              x={labelPos.x}\n              y={labelPos.y}\n              fill={ink}\n              fontSize={n > 8 ? 9 : 11}\n              fontWeight={700}\n              fontFamily=\"'Helvetica Neue', Helvetica, Arial, sans-serif\"\n              textAnchor=\"middle\"\n              dominantBaseline=\"middle\"\n              transform={`rotate(${textAngle}, ${labelPos.x}, ${labelPos.y})`}\n              style={{ letterSpacing: \"0.04em\" }}\n            >\n              {seg.label.length > 12 ? seg.label.slice(0, 11) + \"…\" : seg.label}\n            </text>\n          </g>\n        );\n      })}\n\n      <circle cx={cx} cy={cy} r={size * 0.09} fill=\"#0a0a0f\" stroke={accentColor} strokeWidth={2} />\n      <circle cx={cx} cy={cy} r={size * 0.035} fill={accentColor} />\n\n      {segments.map((_, i) => {\n        const a = i * slice;\n        const outer = polar(a, r - 2);\n        const inner = polar(a, r - 10);\n        return <line key={`tick-${i}`} x1={inner.x} y1={inner.y} x2={outer.x} y2={outer.y} stroke={inkSoft} strokeWidth={1.5} />;\n      })}\n    </svg>\n  );\n}\n\nfunction Pointer({ accentColor }: { accentColor: string }) {\n  return (\n    <div className=\"absolute -top-1.5 left-1/2 z-[5] -translate-x-1/2\" style={{ filter: \"drop-shadow(0 4px 8px rgba(0,0,0,0.45))\" }} aria-hidden=\"true\">\n      <svg width=\"28\" height=\"36\" viewBox=\"0 0 28 36\">\n        <path d=\"M14 34 L2 4 Q14 10 26 4 Z\" fill={accentColor} stroke=\"rgba(0,0,0,0.35)\" strokeWidth=\"1\" />\n        <circle cx=\"14\" cy=\"8\" r=\"3.5\" fill=\"#0a0a0f\" />\n      </svg>\n    </div>\n  );\n}\n\nexport interface SpinToWinWheelProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  accentColor?: string;\n  theme?: keyof typeof THEMES;\n  asPopup?: boolean;\n  /** Only used when asPopup is true — starts the popup open instead of showing the launcher widget. */\n  defaultOpen?: boolean;\n  trigger?: \"manual\" | \"delay\" | \"scroll\";\n  delaySeconds?: number;\n  widgetPosition?: \"bottom-right\" | \"bottom-left\";\n  widgetIcon?: string;\n  storageKey?: string;\n  freeSpins?: number;\n  spinDuration?: number;\n}\n\n/**\n * SpinToWinWheel — a gamified discount-capture widget: spin a\n * weighted prize wheel (SVG segments, \"Try Again\" outcomes stay eligible for\n * another spin) for a reward, with a themed reveal modal and code copy.\n * Renders inline, or as a corner-launched popup with manual/delay/scroll\n * triggers.\n */\nexport function SpinToWinWheel({\n  className,\n  accentColor = \"#ffffff\",\n  theme = \"ecommerce\",\n  asPopup = false,\n  defaultOpen = false,\n  trigger = \"manual\",\n  delaySeconds = 4,\n  widgetPosition = \"bottom-right\",\n  widgetIcon,\n  storageKey = \"\",\n  freeSpins = 3,\n  spinDuration = 4.2,\n  ...props\n}: SpinToWinWheelProps) {\n  const uid = React.useId();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const popupCardRef = React.useRef<HTMLDivElement>(null);\n  const rewardModalRef = React.useRef<HTMLDivElement>(null);\n  const widgetTriggerRef = React.useRef<HTMLButtonElement>(null);\n  const widgetContainerRef = React.useRef<HTMLDivElement>(null);\n  const cardRef = React.useRef<HTMLDivElement>(null);\n  const spinTimerRef = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n  const settleTimerRef = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n  const copyTimerRef = React.useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n\n  const [rotation, setRotation] = React.useState(0);\n  const [isSpinning, setIsSpinning] = React.useState(false);\n  const [currentReward, setCurrentReward] = React.useState<Reward | null>(null);\n  const [showPopup, setShowPopup] = React.useState(false);\n  const [rewards, setRewards] = React.useState<Reward[]>([]);\n  const [spinsLeft, setSpinsLeft] = React.useState(freeSpins);\n  const [message, setMessage] = React.useState(`You have ${freeSpins} free spins`);\n  const [copiedCode, setCopiedCode] = React.useState<string | null>(null);\n  const [lastLabel, setLastLabel] = React.useState<string | null>(null);\n\n  const [popupOpen, setPopupOpen] = React.useState(!asPopup || defaultOpen);\n  const [scrollTriggered, setScrollTriggered] = React.useState(false);\n  const [widgetHover, setWidgetHover] = React.useState(false);\n  const [widgetVisible, setWidgetVisible] = React.useState(true);\n  const [prevAsPopup, setPrevAsPopup] = React.useState(asPopup);\n\n  if (asPopup !== prevAsPopup) {\n    setPrevAsPopup(asPopup);\n    setPopupOpen(!asPopup || defaultOpen);\n  }\n\n  const activeTheme = THEMES[theme] || THEMES.ecommerce;\n  const segments = activeTheme.segments;\n  const duration = Math.max(2.2, Math.min(8, spinDuration));\n  const wheelSize = 280;\n\n  const mode = {\n    ink: \"#ffffff\",\n    inkSoft: \"rgba(255,255,255,0.7)\",\n    inkMuted: \"rgba(255,255,255,0.45)\",\n    inkFaint: \"rgba(255,255,255,0.4)\",\n    divider: \"rgba(255,255,255,0.3)\",\n    surface: \"rgba(255,255,255,0.06)\",\n    surfaceBorder: \"rgba(255,255,255,0.12)\",\n    cardBorder: \"rgba(255,255,255,0.08)\",\n    overlayBg: \"rgba(4,4,6,0.86)\",\n    modalBg: \"rgba(255,255,255,0.06)\",\n    modalBorder: \"rgba(255,255,255,0.16)\",\n    codeBoxBg: \"rgba(255,255,255,0.04)\",\n    codeBoxBorder: \"rgba(255,255,255,0.3)\",\n    chromeBg: \"rgba(10,10,15,0.92)\",\n    chromeBorder: \"rgba(255,255,255,0.16)\",\n    iconStroke: \"rgba(255,255,255,0.6)\",\n    wheelGlow: \"rgba(0,0,0,0.55)\",\n  };\n\n  const suffix = storageKey.trim() ? `-${storageKey.trim()}` : \"\";\n  const spinsKey = `spin-spins-left${suffix}`;\n  const rewardsKey = `spin-rewards${suffix}`;\n\n  React.useEffect(() => {\n    const savedSpins = localStorage.getItem(spinsKey);\n    const savedRewards = localStorage.getItem(rewardsKey);\n    if (savedSpins !== null) setSpinsLeft(parseInt(savedSpins, 10));\n    if (savedRewards) {\n      try {\n        setRewards(JSON.parse(savedRewards));\n      } catch {\n        setRewards([]);\n      }\n    }\n    if (savedSpins === \"0\") setMessage(\"All spins used\");\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, []);\n\n  React.useEffect(() => {\n    return () => {\n      clearTimeout(spinTimerRef.current);\n      clearTimeout(settleTimerRef.current);\n      clearTimeout(copyTimerRef.current);\n    };\n  }, []);\n\n  React.useEffect(() => {\n    if (!asPopup || trigger !== \"delay\") return;\n    const t = setTimeout(() => setPopupOpen(true), delaySeconds * 1000);\n    return () => clearTimeout(t);\n  }, [asPopup, trigger, delaySeconds]);\n\n  React.useEffect(() => {\n    if (!asPopup || trigger !== \"scroll\" || !rootRef.current) return;\n    const observer = new IntersectionObserver(\n      ([entry]) => {\n        if (entry.isIntersecting && !scrollTriggered) {\n          setScrollTriggered(true);\n          setPopupOpen(true);\n        }\n      },\n      { threshold: 0.4 }\n    );\n    observer.observe(rootRef.current);\n    return () => observer.disconnect();\n  }, [asPopup, trigger, scrollTriggered]);\n\n  React.useEffect(() => {\n    if (!asPopup || !widgetContainerRef.current) return;\n    const el = widgetContainerRef.current;\n    const observer = new IntersectionObserver(([entry]) => setWidgetVisible(entry.isIntersecting), { threshold: 0 });\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, [asPopup]);\n\n  const wasPopupOpenRef = React.useRef(false);\n  React.useEffect(() => {\n    if (!asPopup) return;\n    if (popupOpen) {\n      popupCardRef.current?.focus();\n    } else if (wasPopupOpenRef.current) {\n      widgetTriggerRef.current?.focus();\n    }\n    wasPopupOpenRef.current = popupOpen;\n  }, [asPopup, popupOpen]);\n\n  React.useEffect(() => {\n    if (!showPopup) return;\n    rewardModalRef.current?.focus();\n  }, [showPopup]);\n\n  /** Target CSS rotation so segment `index` lands under the top pointer. */\n  const rotationForIndex = (index: number, current: number) => {\n    const n = segments.length;\n    const midAngle = index * (360 / n) + 360 / n / 2;\n    const extraTurns = 4 + Math.floor(Math.random() * 3); // 4-6 extra full turns for drama\n    const jitter = (Math.random() - 0.5) * (360 / n) * 0.55; // land off dead-center\n    const targetMod = (360 - (midAngle + jitter) + 360) % 360;\n    const base = Math.ceil(current / 360) * 360 + extraTurns * 360 + targetMod;\n    return base <= current ? base + 360 : base;\n  };\n\n  const finishSpin = (index: number, nextSpinsLeft: number, nextRewards: Reward[]) => {\n    const seg = segments[index];\n    const won: Reward = { label: seg.label, code: seg.code };\n    const isRetry = /retry|try again/i.test(seg.label);\n\n    setCurrentReward(won);\n    setLastLabel(seg.label);\n    setIsSpinning(false);\n\n    if (!isRetry) {\n      setRewards(nextRewards);\n      localStorage.setItem(rewardsKey, JSON.stringify(nextRewards));\n    }\n\n    setSpinsLeft(nextSpinsLeft);\n    localStorage.setItem(spinsKey, nextSpinsLeft.toString());\n    setMessage(nextSpinsLeft === 0 ? \"All spins used\" : `${nextSpinsLeft} spin${nextSpinsLeft > 1 ? \"s\" : \"\"} left`);\n    settleTimerRef.current = setTimeout(() => setShowPopup(true), 450);\n  };\n\n  const spinWheel = () => {\n    if (spinsLeft <= 0 || isSpinning) return;\n    setIsSpinning(true);\n    setShowPopup(false);\n    setCurrentReward(null);\n    setMessage(\"Spinning...\");\n    clearTimeout(spinTimerRef.current);\n    clearTimeout(settleTimerRef.current);\n\n    const index = pickWeightedIndex(segments);\n    const nextRot = rotationForIndex(index, rotation);\n    setRotation(nextRot);\n\n    const nextSpinsLeft = spinsLeft - 1;\n    const seg = segments[index];\n    const isRetry = /retry|try again/i.test(seg.label);\n    const nextRewards = isRetry ? rewards : [...rewards, { label: seg.label, code: seg.code }];\n\n    spinTimerRef.current = setTimeout(() => {\n      finishSpin(index, nextSpinsLeft, nextRewards);\n    }, duration * 1000 + 80);\n  };\n\n  const copyCode = (code: string) => {\n    navigator.clipboard.writeText(code).catch(() => {});\n    setCopiedCode(code);\n    clearTimeout(copyTimerRef.current);\n    copyTimerRef.current = setTimeout(() => setCopiedCode(null), 1500);\n  };\n\n  const widgetOnRight = widgetPosition !== \"bottom-left\";\n\n  const gameCard = (\n    <div\n      ref={cardRef}\n      className=\"relative box-border flex w-full min-w-0 flex-col items-center justify-start overflow-hidden px-[26px] py-8 select-none\"\n      style={{\n        background: activeTheme.background,\n        border: `1px solid ${mode.cardBorder}`,\n        fontFamily: \"'Helvetica Neue', Helvetica, Arial, sans-serif\",\n        ...(asPopup ? { height: \"auto\", minHeight: 0, maxHeight: \"90vh\", overflowY: \"auto\" } : {}),\n      }}\n    >\n      <div className=\"relative z-[1] mb-[18px] text-center\">\n        <h2\n          id={`${uid}-title`}\n          className=\"m-0 text-[25px] font-normal leading-[1.15] tracking-[-0.02em]\"\n          style={{ color: mode.ink, fontFamily: \"Georgia, 'Times New Roman', serif\" }}\n        >\n          {activeTheme.title}\n        </h2>\n        <div className=\"mx-auto my-3 h-px w-8\" style={{ background: mode.divider }} />\n        <div className=\"text-[10px] font-semibold uppercase tracking-[0.18em]\" style={{ color: mode.inkFaint }}>\n          {activeTheme.subtitle}\n        </div>\n      </div>\n\n      <div className=\"relative z-[1] mb-5 flex items-center justify-center pt-2.5\">\n        <div\n          className=\"relative rounded-full\"\n          style={{ padding: 6, boxShadow: `0 0 0 1px ${mode.surfaceBorder}, 0 18px 40px ${mode.wheelGlow}, 0 0 60px ${activeTheme.glow}` }}\n        >\n          <Pointer accentColor={accentColor} />\n          <motion.div\n            animate={{ rotate: rotation }}\n            transition={isSpinning ? { duration, ease: [0.12, 0.8, 0.08, 1] } : { duration: 0.4, ease: \"easeOut\" }}\n            style={{ width: wheelSize, height: wheelSize, borderRadius: \"50%\", willChange: \"transform\" }}\n          >\n            <WheelFace segments={segments} accentColor={accentColor} size={wheelSize} />\n          </motion.div>\n        </div>\n      </div>\n\n      <div\n        className=\"relative z-[1] mb-2.5 w-full max-w-[260px] rounded-[14px] px-4 py-3 text-center backdrop-blur-[8px]\"\n        style={{ background: mode.surface, border: `1px solid ${mode.surfaceBorder}` }}\n      >\n        <div className=\"text-[10px] font-bold uppercase tracking-[0.2em]\" style={{ color: mode.inkFaint }}>\n          Result\n        </div>\n        <div className=\"font-normal\" style={{ color: mode.ink, fontFamily: \"Georgia, 'Times New Roman', serif\", fontSize: 22, marginTop: 2 }} aria-live=\"polite\">\n          {lastLabel ?? \"-\"}\n        </div>\n      </div>\n\n      <div className=\"relative z-[1] mb-[18px] text-center text-xs font-semibold uppercase tracking-[0.08em]\" style={{ color: mode.inkMuted }} aria-live=\"polite\">\n        {message}\n      </div>\n\n      <motion.button\n        onClick={spinWheel}\n        whileHover={{ scale: spinsLeft <= 0 || isSpinning ? 1 : 1.03 }}\n        whileTap={{ scale: spinsLeft <= 0 || isSpinning ? 1 : 0.97 }}\n        disabled={spinsLeft <= 0 || isSpinning}\n        className=\"relative z-[1] mb-[26px] rounded-[40px] border-none px-[30px] py-3.5 text-xs font-bold uppercase tracking-[0.1em] text-[#0a0a0f]\"\n        style={{\n          background: accentColor,\n          opacity: spinsLeft <= 0 || isSpinning ? 0.4 : 1,\n          cursor: spinsLeft <= 0 || isSpinning ? \"not-allowed\" : \"pointer\",\n        }}\n      >\n        {isSpinning ? \"Spinning...\" : spinsLeft <= 0 ? \"No Spins Left\" : `${activeTheme.buttonText} · ${spinsLeft} left`}\n      </motion.button>\n\n      {rewards.length > 0 && (\n        <div className=\"relative z-[1] mt-1.5 w-full max-w-[340px]\">\n          <div className=\"mb-3 text-center text-[10px] font-bold uppercase tracking-[0.2em]\" style={{ color: mode.inkFaint }}>\n            Your Rewards\n          </div>\n          <div className=\"flex flex-col gap-2\">\n            {rewards.map((r, i) => {\n              const isCopied = copiedCode === r.code;\n              return (\n                <div\n                  key={`${r.code}-${i}`}\n                  className=\"flex items-center justify-between rounded-[12px] px-4 py-3 backdrop-blur-[8px]\"\n                  style={{ background: mode.surface, border: `1px solid ${mode.surfaceBorder}` }}\n                >\n                  <div>\n                    <div className=\"text-sm font-semibold\" style={{ color: mode.ink }}>\n                      {r.label}\n                    </div>\n                    <div className=\"mt-0.5 text-[11px] font-semibold tracking-[0.06em]\" style={{ color: mode.inkFaint }}>\n                      {r.code}\n                    </div>\n                  </div>\n                  <button\n                    onClick={() => copyCode(r.code)}\n                    className=\"flex items-center justify-center rounded-[8px] border-none bg-transparent p-1.5\"\n                    title=\"Copy code\"\n                    aria-label=\"Copy code\"\n                  >\n                    {isCopied ? (\n                      <span style={{ color: mode.ink, fontSize: 14, fontWeight: 700 }}>✓</span>\n                    ) : (\n                      <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke={mode.iconStroke} strokeWidth=\"2\">\n                        <rect x=\"9\" y=\"9\" width=\"13\" height=\"13\" rx=\"2\" ry=\"2\" />\n                        <path d=\"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1\" />\n                      </svg>\n                    )}\n                  </button>\n                </div>\n              );\n            })}\n          </div>\n        </div>\n      )}\n\n      <AnimatePresence>\n        {showPopup && currentReward && (\n          <motion.div\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0, transition: { duration: 0.12 } }}\n            className=\"absolute inset-0 z-50 flex items-center justify-center p-4 backdrop-blur-[6px]\"\n            style={{ background: mode.overlayBg }}\n          >\n            <motion.div\n              ref={rewardModalRef}\n              initial={{ opacity: 0, scale: 0.96 }}\n              animate={{ opacity: 1, scale: 1 }}\n              exit={{ opacity: 0, scale: 0.98 }}\n              transition={{ duration: 0.35, ease: [0.16, 1, 0.3, 1] }}\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-labelledby={`${uid}-reward-title`}\n              tabIndex={-1}\n              onKeyDown={(e) => {\n                if (e.key === \"Escape\") setShowPopup(false);\n              }}\n              className=\"w-full max-w-[300px] px-[26px] py-[30px] text-center backdrop-blur-[20px]\"\n              style={{ background: mode.modalBg, border: `1px solid ${mode.modalBorder}`, boxShadow: \"0 20px 50px rgba(0,0,0,0.5)\" }}\n            >\n              <motion.h3\n                id={`${uid}-reward-title`}\n                initial={{ opacity: 0, y: 14 }}\n                animate={{ opacity: 1, y: 0 }}\n                transition={{ delay: 0.15, duration: 0.4 }}\n                className=\"m-0 text-2xl font-normal\"\n                style={{ color: mode.ink, fontFamily: \"Georgia, 'Times New Roman', serif\" }}\n              >\n                {/retry|try again/i.test(currentReward.label) ? \"Almost!\" : \"You won\"}\n              </motion.h3>\n              <motion.div\n                initial={{ scaleX: 0 }}\n                animate={{ scaleX: 1 }}\n                transition={{ delay: 0.25, duration: 0.4 }}\n                className=\"mx-auto my-3 mb-3.5 h-px w-7 origin-center\"\n                style={{ background: mode.divider }}\n              />\n              <motion.p\n                initial={{ opacity: 0, y: 10 }}\n                animate={{ opacity: 1, y: 0 }}\n                transition={{ delay: 0.3, duration: 0.4 }}\n                className=\"m-0 mb-[18px] text-[15px]\"\n                style={{ color: mode.inkSoft }}\n              >\n                {currentReward.label}\n              </motion.p>\n              {!/retry|try again/i.test(currentReward.label) && (\n                <motion.div\n                  initial={{ opacity: 0, y: 10 }}\n                  animate={{ opacity: 1, y: 0 }}\n                  transition={{ delay: 0.35, duration: 0.4 }}\n                  className=\"mb-5 rounded-[10px] border border-dashed p-3\"\n                  style={{ background: mode.codeBoxBg, borderColor: mode.codeBoxBorder }}\n                >\n                  <span className=\"text-base font-bold tracking-[0.06em]\" style={{ color: mode.ink }}>\n                    {currentReward.code}\n                  </span>\n                </motion.div>\n              )}\n              <motion.button\n                initial={{ opacity: 0, y: 10 }}\n                animate={{ opacity: 1, y: 0 }}\n                transition={{ delay: 0.4, duration: 0.4 }}\n                onClick={() => setShowPopup(false)}\n                className=\"w-full cursor-pointer rounded-[40px] border-none px-[13px] py-[13px] text-xs font-bold uppercase tracking-[0.1em] text-[#0a0a0f]\"\n                style={{ background: accentColor }}\n              >\n                Continue\n              </motion.button>\n            </motion.div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n\n  if (!asPopup) {\n    return (\n      <div ref={rootRef} className={cn(\"w-full\", className)} {...props}>\n        {gameCard}\n      </div>\n    );\n  }\n\n  return (\n    <div ref={rootRef} className={cn(\"relative\", className)} {...props}>\n      <div\n        ref={widgetContainerRef}\n        className=\"fixed bottom-6 z-[9998] flex items-center gap-2.5\"\n        style={{ flexDirection: widgetOnRight ? \"row-reverse\" : \"row\", ...(widgetOnRight ? { right: 24 } : { left: 24 }) }}\n      >\n        <motion.button\n          ref={widgetTriggerRef}\n          onClick={() => setPopupOpen(true)}\n          onHoverStart={() => setWidgetHover(true)}\n          onHoverEnd={() => setWidgetHover(false)}\n          whileHover={{ scale: 1.06 }}\n          whileTap={{ scale: 0.94 }}\n          aria-label={activeTheme.triggerText}\n          className=\"relative flex h-14 w-14 shrink-0 cursor-pointer items-center justify-center rounded-full backdrop-blur-[10px]\"\n          style={{ background: mode.chromeBg, border: `1px solid ${mode.chromeBorder}`, boxShadow: `0 8px 28px ${activeTheme.glow}, 0 4px 14px rgba(0,0,0,0.5)` }}\n        >\n          <motion.span\n            className=\"pointer-events-none absolute inset-0 rounded-full\"\n            style={{ background: \"rgba(255,255,255,0.7)\" }}\n            animate={!widgetVisible ? undefined : { scale: [1, 1.7, 1.7], opacity: [0.4, 0, 0] }}\n            transition={!widgetVisible ? { duration: 0 } : { duration: 2.2, repeat: Infinity, ease: \"easeOut\" }}\n          />\n          {widgetIcon ? <img src={widgetIcon} alt=\"\" className=\"relative h-7 w-7 rounded-full object-cover\" /> : <GiftIcon />}\n        </motion.button>\n\n        <AnimatePresence>\n          {widgetHover && (\n            <motion.div\n              initial={{ opacity: 0, x: widgetOnRight ? 10 : -10 }}\n              animate={{ opacity: 1, x: 0 }}\n              exit={{ opacity: 0, x: widgetOnRight ? 10 : -10 }}\n              transition={{ duration: 0.18 }}\n              className=\"whitespace-nowrap rounded-[10px] px-4 py-2.5 text-[11px] font-semibold uppercase tracking-[0.06em] backdrop-blur-[10px]\"\n              style={{ background: mode.chromeBg, border: `1px solid ${mode.chromeBorder}`, color: mode.ink }}\n            >\n              {activeTheme.triggerText}\n            </motion.div>\n          )}\n        </AnimatePresence>\n      </div>\n\n      <AnimatePresence>\n        {popupOpen && (\n          <motion.div\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0 }}\n            className=\"fixed inset-0 z-[9999] flex items-center justify-center p-5 backdrop-blur-[4px]\"\n            style={{ background: \"rgba(0,0,0,0.7)\" }}\n          >\n            <motion.div\n              ref={popupCardRef}\n              initial={{ scale: 0.94, y: 16 }}\n              animate={{ scale: 1, y: 0 }}\n              exit={{ scale: 0.96, opacity: 0 }}\n              transition={{ duration: 0.35, ease: [0.16, 1, 0.3, 1] }}\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-labelledby={`${uid}-title`}\n              tabIndex={-1}\n              onKeyDown={(e) => {\n                if (e.key === \"Escape\") setPopupOpen(false);\n              }}\n              className=\"relative w-full max-w-[420px]\"\n              style={{ maxHeight: \"90vh\" }}\n            >\n              {gameCard}\n              <button\n                onClick={() => setPopupOpen(false)}\n                aria-label=\"Close\"\n                className=\"absolute -right-3.5 -top-3.5 z-[100] flex h-8 w-8 cursor-pointer items-center justify-center rounded-full p-0 text-[17px] leading-[30px]\"\n                style={{ background: mode.chromeBg, border: `1px solid ${mode.chromeBorder}`, color: mode.ink, boxShadow: \"0 4px 16px rgba(0,0,0,0.5)\" }}\n              >\n                ×\n              </button>\n            </motion.div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nexport default SpinToWinWheel;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}