{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "returns-calculator-snippet",
  "type": "registry:component",
  "title": "Returns Calculator Snippet",
  "description": "A responsive returns calculator card snippet that lets users quickly estimate investment outcomes, featuring clear inputs, smooth interactions, and instant visual feedback for confident decision-making.",
  "dependencies": [
    "@number-flow/react",
    "motion"
  ],
  "files": [
    {
      "path": "components/watermelon/returns-calculator-snippet.tsx",
      "type": "registry:component",
      "content": "'use client';\n\nimport { useState, useMemo, type FC, type ChangeEvent } from 'react';\nimport { motion } from 'motion/react';\nimport NumberFlow from '@number-flow/react';\n\n/* --- Types --- */\ninterface SliderProps {\n  value: number;\n  min: number;\n  max: number;\n  onChange: (val: number) => void;\n}\n\ninterface DonutProps {\n  invested: number;\n  returns: number;\n}\n\nexport interface ReturnsCalculatorProps {\n  initialMonthly?: number;\n  initialRate?: number;\n  initialYears?: number;\n  monthlyRange?: { min: number; max: number };\n  rateRange?: { min: number; max: number };\n  yearsRange?: { min: number; max: number };\n}\n\n/* --- Internal Components --- */\nconst AnimatedValue: FC<{\n  value: number | string;\n  prefix?: string;\n  suffix?: string;\n  className?: string;\n}> = ({ value, prefix, suffix, className }) => {\n  return (\n    <NumberFlow\n      value={Number(value)}\n      locales=\"en-IN\"\n      prefix={prefix}\n      suffix={suffix}\n      transformTiming={{\n        easing: 'ease-out',\n        duration: 500,\n      }}\n      className={`font-bold text-[#2B2B2B] dark:text-zinc-100 ${className || 'xs:text-lg text-base sm:text-xl lg:text-2xl'}`}\n    />\n  );\n};\n\nconst Slider: FC<SliderProps> = ({ value, min, max, onChange }) => {\n  const percent = ((value - min) / (max - min)) * 100;\n  return (\n    <div className=\"relative h-12 rounded-full border-b-[1.6px] border-[#E5E5E9] bg-white px-4 sm:h-14 dark:border-zinc-800 dark:bg-zinc-900\">\n      <div className=\"absolute inset-y-1/2 left-1/2 h-1.5 w-[90%] -translate-x-1/2 -translate-y-1/2 rounded-full bg-gray-200 dark:bg-zinc-700\" />\n      <motion.div\n        className=\"absolute inset-y-1/2 h-1.5 -translate-y-1/2 rounded-full bg-black dark:bg-zinc-100\"\n        style={{ width: `${percent * 0.9}%`, left: '5%' }}\n      />\n      <motion.div\n        className=\"absolute top-1/2 z-10 h-6 w-6 -translate-y-1/2 rounded-full border border-gray-200 bg-white shadow-xl sm:h-7 sm:w-7 dark:border-zinc-400 dark:bg-zinc-100\"\n        style={{ left: `calc(${5 + percent * 0.9}% - 12px)` }}\n        transition={{ type: 'spring', bounce: 0.2, duration: 0.3 }}\n      />\n      <input\n        title=\"range\"\n        type=\"range\"\n        min={min}\n        max={max}\n        value={value}\n        onChange={(e: ChangeEvent<HTMLInputElement>) =>\n          onChange(+e.target.value)\n        }\n        className=\"absolute inset-0 z-20 w-full cursor-pointer opacity-0\"\n      />\n    </div>\n  );\n};\n\nconst Donut: FC<DonutProps> = ({ invested, returns }) => {\n  const total = invested + returns;\n  const pReturns = total === 0 ? 0 : returns / total;\n  const pInvested = total === 0 ? 1 : invested / total;\n\n  const C = 2 * Math.PI * 54;\n\n  const gap = 16;\n  const showGap = pReturns > 0 && pInvested > 0;\n  const actualGap = showGap ? gap : 0;\n\n  const investedLength = Math.max(0, pInvested * C - actualGap);\n  const returnLength = Math.max(0, pReturns * C - actualGap);\n\n  return (\n    <div className=\"relative flex shrink-0 justify-center\">\n      <svg\n        width=\"120\"\n        height=\"120\"\n        viewBox=\"0 0 140 140\"\n        className=\"xs:w-[140px] xs:h-[140px] -rotate-90 sm:h-44 sm:w-44\"\n      >\n        <motion.circle\n          cx=\"70\"\n          cy=\"70\"\n          r=\"54\"\n          fill=\"none\"\n          stroke=\"#515158\"\n          className=\"dark:stroke-zinc-400\"\n          strokeWidth=\"20\"\n          strokeLinecap=\"round\"\n          animate={{\n            strokeDasharray: `${investedLength - 6} ${C}`,\n            strokeDashoffset: -(actualGap / 1.5),\n          }}\n          transition={{ type: 'spring', bounce: 0, duration: 0.3 }}\n        />\n        <motion.circle\n          cx=\"70\"\n          cy=\"70\"\n          r=\"54\"\n          fill=\"none\"\n          stroke=\"#D4D3DE\"\n          className=\"dark:stroke-zinc-800\"\n          strokeWidth=\"12\"\n          strokeLinecap={showGap ? 'round' : 'butt'}\n          animate={{\n            strokeDasharray: `${returnLength} ${C}`,\n            strokeDashoffset: -(pInvested * C + actualGap / 2),\n          }}\n          transition={{ type: 'spring', bounce: 0, duration: 0.3 }}\n        />\n      </svg>\n    </div>\n  );\n};\n\nexport const ReturnsCalculator: FC<ReturnsCalculatorProps> = ({\n  initialMonthly = 40000,\n  initialRate = 6,\n  initialYears = 15,\n  monthlyRange = { min: 5000, max: 100000 },\n  rateRange = { min: 1, max: 15 },\n  yearsRange = { min: 1, max: 30 },\n}) => {\n  const [monthly, setMonthly] = useState(initialMonthly);\n  const [rate, setRate] = useState(initialRate);\n  const [years, setYears] = useState(initialYears);\n\n  const invested = monthly * 12 * years;\n  const returns = useMemo(() => {\n    const r = rate / 100 / 12;\n    const n = years * 12;\n    if (r === 0) return 0;\n    return Math.round(monthly * ((Math.pow(1 + r, n) - 1) / r) - invested);\n  }, [monthly, rate, years, invested]);\n\n  return (\n    <div className=\"w-full max-w-lg space-y-8 rounded-[2rem] border-[1.6px] border-[#F0F0F0] bg-[#FEFEFE] p-5 shadow-xl sm:rounded-[2.5rem] md:p-8 lg:py-10 xl:p-10 dark:border-zinc-800 dark:bg-zinc-900\">\n      {/* Top Section */}\n      <div className=\"flex flex-col items-center gap-8 lg:items-start lg:gap-12 xl:flex-row xl:items-center\">\n        <Donut invested={invested} returns={returns} />\n\n        {/* Stats Section*/}\n        <div className=\"xs:grid-cols-2 grid w-full grid-cols-1 gap-6 lg:grid-cols-1\">\n          <div className=\"flex items-start gap-3 sm:gap-4\">\n            <span className=\"mt-1.5 h-3.5 w-3.5 shrink-0 rounded-full bg-[#D4D3DE] dark:bg-zinc-800\" />\n            <div className=\"flex flex-col gap-0.5\">\n              <p className=\"text-xs font-semibold tracking-wider text-[#838385] uppercase sm:text-sm dark:text-zinc-500\">\n                Invested\n              </p>\n              <AnimatedValue value={invested} prefix=\"₹\" />\n            </div>\n          </div>\n          <div className=\"flex items-start gap-3 sm:gap-4\">\n            <span className=\"mt-1.5 h-3.5 w-3.5 shrink-0 rounded-full bg-[#515158] dark:bg-zinc-400\" />\n            <div className=\"flex flex-col gap-0.5\">\n              <p className=\"text-xs font-semibold tracking-wider text-[#838385] uppercase sm:text-sm dark:text-zinc-500\">\n                Returns\n              </p>\n              <AnimatedValue value={returns} prefix=\"₹\" />\n            </div>\n          </div>\n        </div>\n      </div>\n\n      {/* Sliders Section */}\n      <div className=\"grid grid-cols-1 gap-4\">\n        {[\n          {\n            label: 'Monthly Investment',\n            val: (\n              <AnimatedValue\n                value={monthly}\n                prefix=\"₹\"\n                className=\"text-sm sm:text-base\"\n              />\n            ),\n            slider: (\n              <Slider\n                min={monthlyRange.min}\n                max={monthlyRange.max}\n                value={monthly}\n                onChange={setMonthly}\n              />\n            ),\n          },\n          {\n            label: 'Return Rate',\n            val: (\n              <AnimatedValue\n                value={rate}\n                suffix=\"%\"\n                className=\"text-sm sm:text-base\"\n              />\n            ),\n            slider: (\n              <Slider\n                min={rateRange.min}\n                max={rateRange.max}\n                value={rate}\n                onChange={setRate}\n              />\n            ),\n          },\n          {\n            label: 'Time Period',\n            val: (\n              <AnimatedValue\n                value={years}\n                suffix=\" Years\"\n                className=\"text-sm sm:text-base\"\n              />\n            ),\n            slider: (\n              <Slider\n                min={yearsRange.min}\n                max={yearsRange.max}\n                value={years}\n                onChange={setYears}\n              />\n            ),\n          },\n        ].map((item, idx) => (\n          <div\n            key={idx}\n            className=\"rounded-3xl border border-[#E5E5E9] bg-[#F4F4FB] transition-all hover:border-[#D4D3DE] sm:rounded-4xl dark:border-zinc-800/50 dark:bg-zinc-800/40 dark:hover:border-zinc-700\"\n          >\n            {item.slider}\n            <div className=\"flex items-center justify-between px-5 py-3\">\n              <span className=\"text-[10px] font-bold tracking-tight text-[#717077] uppercase sm:text-xs dark:text-zinc-400\">\n                {item.label}\n              </span>\n              {item.val}\n            </div>\n          </div>\n        ))}\n      </div>\n    </div>\n  );\n};\n"
    }
  ]
}
