{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "altseason-gauge",
  "title": "Altseason Gauge",
  "description": "Altcoin Season index gauge computed client-side from CoinPaprika data.",
  "dependencies": [
    "framer-motion",
    "@number-flow/react"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/voraui/altseason-gauge/index.ts",
      "content": "export { AltseasonGauge, type AltseasonGaugeProps } from \"./altseason-gauge\";\nexport { AltseasonGaugeSkeleton } from \"./components/skeleton\";\nexport type { AltseasonData, AltseasonWindow } from \"./lib/altseason\";\n",
      "type": "registry:lib",
      "target": "components/voraui/altseason-gauge/index.ts"
    },
    {
      "path": "registry/voraui/altseason-gauge/altseason-gauge.tsx",
      "content": "\"use client\";\n\nimport { motion } from \"framer-motion\";\nimport NumberFlow from \"@number-flow/react\";\nimport { cn } from \"@/lib/utils\";\nimport { AltseasonGaugeSkeleton } from \"./components/skeleton\";\nimport { useAltseason } from \"./hooks/use-altseason\";\nimport type { AltseasonData, AltseasonWindow } from \"./lib/altseason\";\n\nexport interface AltseasonGaugeProps {\n  /** Provide your own data to bypass the bundled CoinPaprika fetcher. */\n  data?: AltseasonData;\n  /** Comparison window for the bundled fetcher. Ignored when data is set. */\n  window?: AltseasonWindow;\n  /** \"meter\" (default) three-zone track with a thumb; \"bars\" one bar per compared altcoin. */\n  variant?: \"meter\" | \"bars\";\n  /** Spring the thumb in from center on first render instead of snapping. */\n  animateOnLoad?: boolean;\n  className?: string;\n}\n\n// Bars fallback when custom data has a score but no per-coin counts.\nconst BARS_FALLBACK_TOTAL = 50;\n\n// Classic altseason spectrum (blockchaincenter.net): amber BTC pole, blue\n// mixed center, red alt pole. Both variants draw from this one ramp.\nconst SEASON_RAMP_STOPS: { t: number; rgb: [number, number, number] }[] = [\n  { t: 0, rgb: [245, 158, 11] },\n  { t: 0.25, rgb: [250, 204, 21] },\n  { t: 0.4, rgb: [74, 222, 128] },\n  { t: 0.5, rgb: [56, 189, 248] },\n  { t: 0.6, rgb: [74, 222, 128] },\n  { t: 0.75, rgb: [250, 204, 21] },\n  { t: 0.88, rgb: [245, 158, 11] },\n  { t: 1, rgb: [239, 68, 68] },\n];\n\nconst TRACK_GRADIENT = `linear-gradient(to right, ${SEASON_RAMP_STOPS.map(\n  (s) => `rgb(${s.rgb.join(\" \")}) ${s.t * 100}%`,\n).join(\", \")})`;\n\nfunction seasonRampColor(t: number): string {\n  for (let i = 0; i < SEASON_RAMP_STOPS.length - 1; i++) {\n    const from = SEASON_RAMP_STOPS[i];\n    const to = SEASON_RAMP_STOPS[i + 1];\n    if (t >= from.t && t <= to.t) {\n      const k = (t - from.t) / (to.t - from.t);\n      const [r, g, b] = from.rgb.map((c, ch) => Math.round(c + (to.rgb[ch] - c) * k));\n      return `rgb(${r} ${g} ${b})`;\n    }\n  }\n  const [r, g, b] = SEASON_RAMP_STOPS[SEASON_RAMP_STOPS.length - 1].rgb;\n  return `rgb(${r} ${g} ${b})`;\n}\n\nexport function AltseasonGauge({\n  data,\n  window: windowProp = \"7d\",\n  variant = \"meter\",\n  animateOnLoad = true,\n  className,\n}: AltseasonGaugeProps) {\n  const fetched = useAltseason(windowProp, { enabled: data === undefined });\n  const resolved = data ?? fetched.data;\n\n  if (!resolved) {\n    if (fetched.error) {\n      return (\n        <div className={cn(\"flex h-[180px] items-center justify-center\", className)}>\n          <p role=\"alert\" className=\"text-xs text-muted-foreground\">Altseason data is unavailable.</p>\n        </div>\n      );\n    }\n    return <AltseasonGaugeSkeleton variant={variant} className={className} />;\n  }\n\n  const hasScore = resolved.score !== null;\n  const score = resolved.score ?? 50;\n  // Edge padding so a 0/100 score doesn't push the thumb half-off the track.\n  const markerLeft = Math.min(Math.max(score, 3), 97);\n  const label = resolved.label;\n  const isBtc = label === \"Bitcoin Season\";\n  const isAlt = label === \"Altcoin Season\";\n  const isMixed = label === \"Mixed\";\n\n  const barsTotal = resolved.compared > 0 ? resolved.compared : BARS_FALLBACK_TOTAL;\n  const barsFilled =\n    resolved.compared > 0\n      ? Math.min(resolved.outperforming, barsTotal)\n      : Math.round((score / 100) * BARS_FALLBACK_TOTAL);\n\n  return (\n    <div className={cn(\"flex flex-col gap-4\", className)}>\n      <div className=\"flex items-end gap-3\">\n        <p className=\"text-4xl font-bold leading-none tabular-nums text-foreground\">\n          {hasScore ? <NumberFlow value={Math.round(resolved.score as number)} /> : \"-\"}\n        </p>\n        <p className=\"pb-1 text-xs text-muted-foreground\">/ 100</p>\n        <span\n          className={cn(\n            \"ml-auto rounded-full px-2.5 py-1 text-[10px] font-semibold uppercase tracking-wider\",\n            isBtc && \"bg-amber-500/10 text-amber-600 dark:bg-amber-400/10 dark:text-amber-300\",\n            isAlt && \"bg-red-500/10 text-red-600 dark:bg-red-400/10 dark:text-red-300\",\n            isMixed && \"bg-sky-500/10 text-sky-600 dark:bg-sky-400/10 dark:text-sky-300\",\n            !isBtc && !isAlt && !isMixed && \"bg-muted text-muted-foreground\",\n          )}\n        >\n          {label}\n        </span>\n      </div>\n\n      {!hasScore ? (\n        <div className=\"flex h-[120px] items-center justify-center\">\n          <p className=\"text-xs text-muted-foreground\">Altseason score is unavailable.</p>\n        </div>\n      ) : variant === \"bars\" ? (\n        <div className=\"flex flex-col gap-3\">\n          <div\n            className=\"flex h-14 items-stretch gap-[3px]\"\n            role=\"img\"\n            aria-label={`${barsFilled} of ${barsTotal} altcoins outperforming Bitcoin`}\n          >\n            {Array.from({ length: barsTotal }, (_, i) => (\n              <div\n                key={i}\n                className={cn(\n                  \"flex-1 rounded-[2px] transition-opacity duration-200\",\n                  i < barsFilled ? \"opacity-100\" : \"opacity-25\",\n                )}\n                style={{ backgroundColor: seasonRampColor(barsTotal > 1 ? i / (barsTotal - 1) : 0) }}\n              />\n            ))}\n          </div>\n          <p className=\"text-xs text-muted-foreground\">\n            <span className=\"font-medium tabular-nums text-foreground\">{barsFilled}</span> of{\" \"}\n            <span className=\"tabular-nums\">{barsTotal}</span> top alts outperforming BTC\n            {resolved.compared > 0 && <> &middot; {resolved.window}</>}\n          </p>\n        </div>\n      ) : (\n        <div className=\"flex flex-col gap-3\">\n          <div className=\"relative\">\n            <div\n              className=\"h-3 w-full rounded-full\"\n              style={{ background: TRACK_GRADIENT }}\n              aria-hidden=\"true\"\n            />\n            <motion.div\n              className=\"pointer-events-none absolute top-1/2 -translate-x-1/2 -translate-y-1/2\"\n              initial={animateOnLoad ? { left: \"50%\" } : false}\n              animate={{ left: `${markerLeft}%` }}\n              transition={{ type: \"spring\", stiffness: 100 }}\n              aria-hidden\n            >\n              <div className=\"h-6 w-1 rounded-full bg-foreground ring-1 ring-background\" />\n            </motion.div>\n          </div>\n          <div className=\"flex justify-between text-[10px] font-medium uppercase tracking-wider text-muted-foreground\">\n            <span className={cn(isBtc && \"text-amber-600 dark:text-amber-300\")}>BTC season</span>\n            <span className={cn(isMixed && \"text-sky-600 dark:text-sky-300\")}>Mixed</span>\n            <span className={cn(isAlt && \"text-red-600 dark:text-red-300\")}>Altseason</span>\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/voraui/altseason-gauge/altseason-gauge.tsx"
    },
    {
      "path": "registry/voraui/altseason-gauge/components/skeleton.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface AltseasonGaugeSkeletonProps {\n  /** Matches AltseasonGaugeProps[\"variant\"] so the ghost lines up with the real gauge. */\n  variant?: \"meter\" | \"bars\";\n  className?: string;\n}\n\nconst BARS_GHOST_COUNT = 24;\n\nexport function AltseasonGaugeSkeleton({ variant = \"meter\", className }: AltseasonGaugeSkeletonProps) {\n  return (\n    <div\n      role=\"status\"\n      className={cn(\"voraui-altseason-gauge-skeleton-shimmer relative flex flex-col gap-4 overflow-hidden\", className)}\n    >\n      <style href=\"voraui-altseason-gauge-skeleton\" precedence=\"low\">{`\n        @keyframes voraui-altseason-gauge-skeleton-shimmer {\n          from { transform: translateX(-100%); }\n          to { transform: translateX(100%); }\n        }\n        .voraui-altseason-gauge-skeleton-shimmer::after {\n          content: \"\";\n          position: absolute;\n          inset: 0;\n          background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);\n          animation: voraui-altseason-gauge-skeleton-shimmer 1.8s ease-in-out infinite;\n        }\n        @media (prefers-reduced-motion: reduce) {\n          .voraui-altseason-gauge-skeleton-shimmer::after {\n            animation: none;\n          }\n        }\n      `}</style>\n      <div className=\"flex items-end gap-3\">\n        <div className=\"h-9 w-14 rounded-md bg-muted\" />\n        <div className=\"h-4 w-8 rounded bg-muted\" />\n        <div className=\"ml-auto h-6 w-24 rounded-full bg-muted\" />\n      </div>\n\n      {variant === \"bars\" ? (\n        <div className=\"flex flex-col gap-3\">\n          <div className=\"flex h-14 items-stretch gap-[3px]\">\n            {Array.from({ length: BARS_GHOST_COUNT }, (_, i) => (\n              <div\n                key={i}\n                className={cn(\"flex-1 rounded-[2px] bg-muted\", i % 2 === 0 ? \"opacity-60\" : \"opacity-25\")}\n              />\n            ))}\n          </div>\n          <div className=\"h-4 w-40 rounded bg-muted\" />\n        </div>\n      ) : (\n        <div className=\"flex flex-col gap-3\">\n          <div className=\"h-3 w-full rounded-full bg-muted\" />\n          <div className=\"flex justify-between\">\n            <div className=\"h-3 w-16 rounded bg-muted\" />\n            <div className=\"h-3 w-12 rounded bg-muted\" />\n            <div className=\"h-3 w-16 rounded bg-muted\" />\n          </div>\n        </div>\n      )}\n      <span className=\"sr-only\">Loading Altseason Index</span>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/voraui/altseason-gauge/components/skeleton.tsx"
    },
    {
      "path": "registry/voraui/altseason-gauge/hooks/use-altseason.ts",
      "content": "\"use client\";\n\nimport { useEffect, useState } from \"react\";\nimport {\n  computeAltseason,\n  type AltseasonData,\n  type AltseasonWindow,\n  type PaprikaTicker,\n} from \"../lib/altseason\";\n\n// CoinPaprika public tickers. Free, no API key; large response but fetched rarely.\nconst TICKERS_URL = \"https://api.coinpaprika.com/v1/tickers?quotes=USD\";\n\nasync function fetchTickersFromCoinPaprika(): Promise<PaprikaTicker[]> {\n  const res = await fetch(TICKERS_URL);\n  if (!res.ok) throw new Error(`CoinPaprika request failed: ${res.status}`);\n  const raw = (await res.json()) as PaprikaTicker[];\n  return Array.isArray(raw) ? raw : [];\n}\n\n/** Retry transient CoinPaprika failures a couple of times before giving up. */\nexport async function fetchTickersWithRetry(\n  fetchTickers: () => Promise<PaprikaTicker[]> = fetchTickersFromCoinPaprika,\n  attempts = 3,\n  retryDelayMs = 1000,\n): Promise<PaprikaTicker[]> {\n  let lastError: unknown;\n  for (let attempt = 1; attempt <= attempts; attempt++) {\n    try {\n      return await fetchTickers();\n    } catch (err) {\n      lastError = err;\n      if (attempt < attempts) {\n        await new Promise((resolve) => setTimeout(resolve, retryDelayMs));\n      }\n    }\n  }\n  throw lastError;\n}\n\nexport function useAltseason(\n  window: AltseasonWindow = \"7d\",\n  options: { enabled?: boolean; refreshInterval?: number } = {},\n) {\n  const { enabled = true, refreshInterval = 1_800_000 } = options;\n  const [data, setData] = useState<AltseasonData | null>(null);\n  const [loading, setLoading] = useState(enabled);\n  const [error, setError] = useState<string | null>(null);\n\n  useEffect(() => {\n    if (!enabled) return;\n    let cancelled = false;\n\n    const load = async () => {\n      try {\n        const raw = await fetchTickersWithRetry();\n        if (cancelled) return;\n        setData(computeAltseason(raw, window));\n        setError(null);\n        setLoading(false);\n      } catch (err) {\n        if (cancelled) return;\n        setError(err instanceof Error ? err.message : \"CoinPaprika request failed\");\n        setLoading(false);\n      }\n    };\n\n    load();\n    const timer = setInterval(load, refreshInterval);\n    return () => {\n      cancelled = true;\n      clearInterval(timer);\n    };\n  }, [enabled, refreshInterval, window]);\n\n  return { data, loading, error };\n}\n",
      "type": "registry:hook",
      "target": "components/voraui/altseason-gauge/hooks/use-altseason.ts"
    },
    {
      "path": "registry/voraui/altseason-gauge/lib/altseason.ts",
      "content": "export type AltseasonWindow = \"24h\" | \"7d\";\n\nexport type AltseasonLabel = \"Altcoin Season\" | \"Bitcoin Season\" | \"Mixed\" | \"Unknown\";\n\nexport interface PaprikaTicker {\n  symbol?: string | null;\n  rank?: number | null;\n  quotes?: { USD?: Partial<Record<string, number | null>> } | null;\n}\n\nexport interface AltseasonData {\n  /** 0-100 score, or null when it cannot be computed. */\n  score: number | null;\n  label: AltseasonLabel;\n  /** BTC change over the window, in percent. */\n  btcChangePct: number | null;\n  window: AltseasonWindow;\n  /** Number of alts included in the comparison (up to 50). */\n  compared: number;\n  /** Number of those alts outperforming BTC. */\n  outperforming: number;\n}\n\n/** CoinPaprika column suffixes under quotes.USD, per window. */\nexport const WINDOW_KEYS: Record<AltseasonWindow, string> = {\n  \"24h\": \"percent_change_24h\",\n  \"7d\": \"percent_change_7d\",\n};\n\n/** Stablecoins and wrapped/liquid-staked BTC/ETH derivatives, which would double-count. */\nexport const ALTSEASON_EXCLUDED_SYMBOLS = new Set([\n  \"USDT\", \"USDC\", \"DAI\", \"BUSD\", \"TUSD\", \"FDUSD\", \"PYUSD\", \"USDD\", \"USDE\", \"USDS\",\n  \"WBTC\", \"BTCB\", \"WETH\", \"STETH\", \"WSTETH\", \"RETH\", \"WEETH\", \"CBBTC\", \"TBTC\",\n]);\n\n/** Altcoin Season Index: % of the top-50 clean alts outperforming BTC over the\n *  window. >= 75 is Altcoin Season, <= 25 is Bitcoin Season (blockchaincenter.net). */\nexport function computeAltseason(\n  tickers: PaprikaTicker[],\n  window: AltseasonWindow = \"7d\",\n): AltseasonData {\n  const key = WINDOW_KEYS[window];\n  const rows = [...tickers].sort((a, b) => (a.rank ?? 1_000_000) - (b.rank ?? 1_000_000));\n\n  const changeOf = (row: PaprikaTicker): number | null => {\n    const value = row.quotes?.USD?.[key];\n    return typeof value === \"number\" && Number.isFinite(value) ? value : null;\n  };\n\n  let btcChange: number | null = null;\n  for (const row of rows) {\n    if ((row.symbol ?? \"\").toUpperCase() === \"BTC\") {\n      btcChange = changeOf(row);\n      break;\n    }\n  }\n\n  if (btcChange === null) {\n    return { score: null, label: \"Unknown\", btcChangePct: null, window, compared: 0, outperforming: 0 };\n  }\n\n  const clean = rows\n    .filter((row) => {\n      const symbol = (row.symbol ?? \"\").toUpperCase();\n      return symbol !== \"BTC\" && !ALTSEASON_EXCLUDED_SYMBOLS.has(symbol) && changeOf(row) !== null;\n    })\n    .slice(0, 50);\n\n  // An all-zero column is a dead upstream column, not a flat market; treat as unknown.\n  if (btcChange === 0 && clean.every((row) => changeOf(row) === 0)) {\n    return { score: null, label: \"Unknown\", btcChangePct: null, window, compared: 0, outperforming: 0 };\n  }\n\n  const outperforming = clean.filter((row) => (changeOf(row) as number) > (btcChange as number)).length;\n  const compared = clean.length;\n  const score = compared > 0 ? (outperforming / compared) * 100 : null;\n\n  const label: AltseasonLabel =\n    score === null ? \"Unknown\" : score >= 75 ? \"Altcoin Season\" : score <= 25 ? \"Bitcoin Season\" : \"Mixed\";\n\n  return {\n    score: score === null ? null : Math.round(score * 10) / 10,\n    label,\n    btcChangePct: Math.round(btcChange * 100) / 100,\n    window,\n    compared,\n    outperforming,\n  };\n}\n",
      "type": "registry:lib",
      "target": "components/voraui/altseason-gauge/lib/altseason.ts"
    }
  ],
  "type": "registry:block"
}