{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "budget-card-base",
  "type": "registry:component",
  "title": "Budget Card (base)",
  "description": "Theme-ready base variant of Budget overview card tracking spending, limits, and remaining balance..",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "files": [
    {
      "path": "components/watermelon/budget-card.tsx",
      "type": "registry:component",
      "content": "'use client';\n\nimport React, { useState, useRef, useEffect } from 'react';\nimport { motion, AnimatePresence } from 'motion/react';\nimport { ChevronDown, Check, X } from 'lucide-react';\n\ninterface BreakdownItem {\n  label: string;\n  amount: number;\n  color: string;\n}\n\ninterface BudgetCardProps {\n  month: string;\n  totalBudget: number;\n  spentAmount: number;\n  breakdown: BreakdownItem[];\n  onViewDetails?: () => void;\n  onMonthChange?: (month: string) => void;\n}\n\nconst months = [\n  'January',\n  'February',\n  'March',\n  'April',\n  'May',\n  'June',\n  'July',\n  'August',\n  'September',\n  'October',\n  'November',\n  'December',\n];\n\nexport const BudgetCard: React.FC<BudgetCardProps> = ({\n  month: initialMonth,\n  totalBudget,\n  spentAmount,\n  breakdown,\n  onViewDetails,\n  onMonthChange,\n}) => {\n  const [selectedMonth, setSelectedMonth] = useState(initialMonth);\n  const [isDropdownOpen, setIsDropdownOpen] = useState(false);\n  const [isDetailsOpen, setIsDetailsOpen] = useState(false);\n  const dropdownRef = useRef<HTMLDivElement>(null);\n\n  const spentPercentage = Math.round((spentAmount / totalBudget) * 100);\n  const remainingAmount = totalBudget - spentAmount;\n\n  const smoothTransition = { duration: 1.5, ease: [0.19, 1, 0.22, 1] } as const;\n  const cornerClass = 'absolute w-5 h-5 border-black/20 dark:border-white/20';\n\n  // Mock Transactions for base view (themed)\n  const transactions = [\n    {\n      id: 1,\n      date: 'Jul 12',\n      name: 'Whole Foods',\n      category: 'Groceries',\n      amount: 84.5,\n    },\n    {\n      id: 2,\n      date: 'Jul 10',\n      name: 'Rent Payment',\n      category: 'Rent',\n      amount: 1600.0,\n    },\n    {\n      id: 3,\n      date: 'Jul 08',\n      name: 'Chevron Gas',\n      category: 'Other',\n      amount: 52.3,\n    },\n  ];\n\n  // Click outside logic\n  useEffect(() => {\n    const handleClickOutside = (event: MouseEvent) => {\n      if (\n        dropdownRef.current &&\n        !dropdownRef.current.contains(event.target as Node)\n      ) {\n        setIsDropdownOpen(false);\n      }\n    };\n    document.addEventListener('mousedown', handleClickOutside);\n    return () => document.removeEventListener('mousedown', handleClickOutside);\n  }, []);\n\n  const handleMonthSelect = (m: string) => {\n    setSelectedMonth(m);\n    setIsDropdownOpen(false);\n    if (onMonthChange) onMonthChange(m);\n  };\n\n  return (\n    <div className=\"theme-injected relative mx-auto w-full max-w-lg\">\n      <motion.div\n        initial={{ opacity: 0, y: 20, scale: 0.98 }}\n        animate={{ opacity: 1, y: 0, scale: 1 }}\n        transition={{ duration: 0.8, ease: [0.19, 1, 0.22, 1] }}\n        className=\"relative w-full\"\n      >\n        {/* Corner Borders */}\n        <div\n          className={`${cornerClass} top-0 left-0 z-40 border-t-2 border-l-2`}\n        />\n        <div\n          className={`${cornerClass} top-0 right-0 z-40 border-t-2 border-r-2`}\n        />\n        <div\n          className={`${cornerClass} bottom-0 left-0 z-40 border-b-2 border-l-2`}\n        />\n        <div\n          className={`${cornerClass} right-0 bottom-0 z-40 border-r-2 border-b-2`}\n        />\n\n        <div className=\"bg-card border-border text-foreground relative w-full overflow-visible border font-sans shadow-sm dark:shadow-2xl\">\n          {/* Top Section */}\n          <div className=\"p-6 pb-4 sm:p-8\">\n            <div className=\"mb-1 flex items-start justify-between\">\n              <p className=\"text-muted-foreground text-sm font-normal sm:text-lg\">\n                Monthly Budget\n              </p>\n\n              {/* --- Month Dropdown --- */}\n              <div className=\"relative\" ref={dropdownRef}>\n                <button\n                  onClick={() => setIsDropdownOpen(!isDropdownOpen)}\n                  className=\"border-border text-muted-foreground hover:bg-accent flex min-w-32 items-center justify-between gap-2 border bg-transparent px-3 py-1 text-sm font-normal transition-colors sm:gap-4 sm:text-lg\"\n                >\n                  {selectedMonth}\n                  <motion.div animate={{ rotate: isDropdownOpen ? 180 : 0 }}>\n                    <ChevronDown size={16} className=\"text-muted-foreground\" />\n                  </motion.div>\n                </button>\n\n                <AnimatePresence>\n                  {isDropdownOpen && (\n                    <motion.div\n                      initial={{ opacity: 0, y: 10, scale: 0.95 }}\n                      animate={{ opacity: 1, y: 5, scale: 1 }}\n                      exit={{ opacity: 0, y: 10, scale: 0.95 }}\n                      className=\"bg-popover border-border absolute top-full right-0 z-50 w-48 overflow-hidden border shadow-xl\"\n                    >\n                      <div className=\"custom-scrollbar max-h-60 overflow-y-auto py-1\">\n                        {months.map((m) => (\n                          <button\n                            key={m}\n                            onClick={() => handleMonthSelect(m)}\n                            className={`flex w-full items-center justify-between px-4 py-2.5 text-left text-sm transition-colors ${\n                              selectedMonth === m\n                                ? 'bg-accent text-accent-foreground font-medium'\n                                : 'text-muted-foreground hover:bg-accent hover:text-accent-foreground'\n                            }`}\n                          >\n                            {m}\n                            {selectedMonth === m && (\n                              <Check\n                                size={14}\n                                className=\"text-accent-foreground\"\n                              />\n                            )}\n                          </button>\n                        ))}\n                      </div>\n                    </motion.div>\n                  )}\n                </AnimatePresence>\n              </div>\n            </div>\n\n            <h2 className=\"text-foreground mb-6 text-5xl leading-none font-medium tracking-tight sm:mb-10 sm:text-6xl\">\n              ${totalBudget.toLocaleString()}\n            </h2>\n\n            <div className=\"space-y-3\">\n              <p className=\"text-muted-foreground text-sm font-normal sm:text-lg\">\n                Monthly spending limit\n              </p>\n              <div className=\"bg-secondary h-2 w-full overflow-hidden\">\n                <motion.div\n                  initial={{ width: 0 }}\n                  animate={{ width: `${spentPercentage}%` }}\n                  transition={smoothTransition}\n                  className=\"bg-primary h-full\"\n                />\n              </div>\n              <div className=\"flex items-end justify-between pt-1\">\n                <div className=\"space-y-1.5\">\n                  <span className=\"text-muted-foreground block text-xs font-normal capitalize sm:text-sm\">\n                    Spent\n                  </span>\n                  <div className=\"flex items-center gap-2 sm:gap-4\">\n                    <span className=\"text-foreground text-base font-normal sm:text-xl\">\n                      ${spentAmount.toLocaleString()}\n                    </span>\n                    <span className=\"bg-secondary text-muted-foreground border-border border px-1.5 py-0.5 text-xs font-normal\">\n                      {spentPercentage}%\n                    </span>\n                  </div>\n                </div>\n                <div className=\"space-y-2 text-right\">\n                  <span className=\"text-muted-foreground block text-sm font-normal capitalize sm:text-base\">\n                    Remaining\n                  </span>\n                  <span className=\"text-foreground text-base font-normal sm:text-xl\">\n                    ${remainingAmount.toLocaleString()}\n                  </span>\n                </div>\n              </div>\n            </div>\n          </div>\n\n          <div className=\"bg-border h-px w-full\" />\n\n          {/* Bottom Section  */}\n          <div className=\"space-y-6 p-6 pt-7 sm:p-8\">\n            <div className=\"space-y-3\">\n              <p className=\"text-muted-foreground block text-sm font-normal capitalize sm:text-base\">\n                Spending breakdown\n              </p>\n              <div className=\"flex h-2 gap-2\">\n                {breakdown.map((item, idx) => (\n                  <motion.div\n                    key={idx}\n                    initial={{ scaleX: 0 }}\n                    animate={{ scaleX: 1 }}\n                    transition={{ ...smoothTransition, delay: 0.5 + idx * 0.1 }}\n                    className=\"h-full origin-left\"\n                    style={{ flex: item.amount, background: item.color }}\n                  />\n                ))}\n              </div>\n              <div className=\"grid grid-cols-3 gap-2 sm:gap-4\">\n                {breakdown.map((item, idx) => (\n                  <div className=\"flex flex-col gap-1\" key={idx}>\n                    <p className=\"text-muted-foreground block truncate text-xs font-normal capitalize sm:text-sm\">\n                      {item.label}\n                    </p>\n                    <p className=\"text-foreground text-sm font-normal sm:text-lg\">\n                      ${item.amount.toLocaleString()}\n                    </p>\n                  </div>\n                ))}\n              </div>\n            </div>\n            <button\n              onClick={() => {\n                setIsDetailsOpen(true);\n                if (onViewDetails) onViewDetails();\n              }}\n              className=\"border-border text-foreground hover:bg-accent hover:text-accent-foreground w-full border bg-transparent py-3 text-sm font-normal transition-colors\"\n            >\n              View Details\n            </button>\n          </div>\n        </div>\n      </motion.div>\n\n      {/* --- Details Modal (Themed) --- */}\n      <AnimatePresence>\n        {isDetailsOpen && (\n          <div className=\"absolute inset-0 z-50 flex items-center justify-center p-4\">\n            <motion.div\n              initial={{ opacity: 0 }}\n              animate={{ opacity: 1 }}\n              exit={{ opacity: 0 }}\n              onClick={() => setIsDetailsOpen(false)}\n              className=\"bg-background/60 absolute inset-0 backdrop-blur-md\"\n            />\n            <motion.div\n              initial={{ y: 20, opacity: 0, scale: 0.95 }}\n              animate={{ y: 0, opacity: 1, scale: 1 }}\n              exit={{ y: 20, opacity: 0, scale: 0.95 }}\n              transition={{ type: 'spring', damping: 25, stiffness: 300 }}\n              className=\"bg-card border-border text-foreground relative flex max-h-[90%] w-full max-w-lg flex-col overflow-hidden border font-sans shadow-2xl\"\n            >\n              {/* Modal Header */}\n              <div className=\"border-border flex items-center justify-between border-b p-6\">\n                <div>\n                  <h3 className=\"text-lg font-semibold\">Budget Details</h3>\n                  <p className=\"text-muted-foreground text-xs\">\n                    Deep dive into your {selectedMonth} spending\n                  </p>\n                </div>\n                <button\n                  onClick={() => setIsDetailsOpen(false)}\n                  className=\"hover:bg-accent rounded-full p-2 transition-colors\"\n                >\n                  <X size={20} className=\"text-muted-foreground\" />\n                </button>\n              </div>\n\n              {/* Modal Content */}\n              <div className=\"custom-scrollbar flex-1 space-y-8 overflow-y-auto p-6\">\n                {/* Stats Grid */}\n                <div className=\"grid grid-cols-2 gap-3 sm:gap-4\">\n                  <div className=\"bg-accent/50 border-border rounded-lg border p-3 transition-colors sm:p-4\">\n                    <p className=\"text-muted-foreground mb-1 truncate text-[9px] font-medium tracking-wide uppercase sm:text-[10px]\">\n                      Total Budget\n                    </p>\n                    <p className=\"text-lg leading-tight font-medium sm:text-xl\">\n                      ${totalBudget.toLocaleString()}\n                    </p>\n                  </div>\n                  <div className=\"bg-accent/50 border-border rounded-lg border p-3 transition-colors sm:p-4\">\n                    <p className=\"text-muted-foreground mb-1 truncate text-[9px] font-medium tracking-wide uppercase sm:text-[10px]\">\n                      Amount Spent\n                    </p>\n                    <p className=\"text-lg leading-tight font-medium sm:text-xl\">\n                      ${spentAmount.toLocaleString()}\n                    </p>\n                  </div>\n                </div>\n\n                {/* Category Breakdown */}\n                <div className=\"space-y-4\">\n                  <h4 className=\"text-muted-foreground text-xs font-semibold tracking-widest uppercase\">\n                    Category Breakdown\n                  </h4>\n                  <div className=\"space-y-4\">\n                    {breakdown.map((item, idx) => {\n                      const percentage =\n                        spentAmount > 0\n                          ? Math.round((item.amount / spentAmount) * 100)\n                          : 0;\n                      return (\n                        <div key={idx} className=\"space-y-2\">\n                          <div className=\"flex justify-between text-sm\">\n                            <span className=\"font-medium\">{item.label}</span>\n                            <span className=\"text-muted-foreground\">\n                              {percentage}%\n                            </span>\n                          </div>\n                          <div className=\"bg-secondary h-1.5 w-full overflow-hidden rounded-full\">\n                            <motion.div\n                              initial={{ width: 0 }}\n                              animate={{ width: `${percentage}%` }}\n                              className=\"h-full rounded-full\"\n                              style={{ background: item.color }}\n                            />\n                          </div>\n                        </div>\n                      );\n                    })}\n                  </div>\n                </div>\n\n                {/* Transactions History */}\n                <div className=\"space-y-4\">\n                  <h4 className=\"text-muted-foreground text-xs font-semibold tracking-widest uppercase\">\n                    Recent Transactions\n                  </h4>\n                  <div className=\"border-border divide-border divide-y border-t\">\n                    {transactions.map((t) => (\n                      <div\n                        key={t.id}\n                        className=\"hover:bg-accent/50 group -mx-2 flex items-center justify-between gap-2 overflow-hidden rounded-md px-2 py-3 transition-colors sm:gap-4\"\n                      >\n                        <div className=\"flex min-w-0 flex-1 items-center gap-2 sm:gap-3\">\n                          <div className=\"bg-accent text-muted-foreground flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-full text-[10px] font-bold\">\n                            {t.name[0]}\n                          </div>\n                          <div className=\"min-w-0 flex-1\">\n                            <p className=\"truncate text-sm font-medium tracking-tight uppercase\">\n                              {t.name}\n                            </p>\n                            <p className=\"text-muted-foreground truncate text-[10px]\">\n                              {t.category} • {t.date}\n                            </p>\n                          </div>\n                        </div>\n                        <span className=\"flex-shrink-0 text-sm font-medium\">\n                          -${t.amount.toFixed(2)}\n                        </span>\n                      </div>\n                    ))}\n                  </div>\n                </div>\n              </div>\n\n              {/* Modal Footer */}\n              <div className=\"border-border border-t p-6\">\n                <button\n                  onClick={() => setIsDetailsOpen(false)}\n                  className=\"bg-primary text-primary-foreground w-full py-3 font-medium transition-transform hover:opacity-90 active:scale-[0.98]\"\n                >\n                  Close Insights\n                </button>\n              </div>\n            </motion.div>\n          </div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n};\n"
    }
  ]
}
