{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "trade-summary-base",
  "type": "registry:component",
  "title": "Trade Summary (base)",
  "description": "Theme-ready base variant of Concise trade summary card showing positions, performance, and key metrics..",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "files": [
    {
      "path": "components/watermelon/trade-summary.tsx",
      "type": "registry:component",
      "content": "'use client';\n\nimport React from 'react';\nimport { motion, AnimatePresence } from 'motion/react';\nimport {\n  ChevronDown,\n  Search,\n  Plus,\n  MoreHorizontal,\n  Download,\n  RefreshCcw,\n  ChevronLeft,\n  ChevronRight,\n  MoreVertical,\n  X,\n  Check,\n  Loader2,\n  Trash2,\n  Copy,\n  Edit2,\n} from 'lucide-react';\n\n/* ---------- Types ---------- */\nexport interface TradeItem {\n  id: string;\n  asset: string;\n  session: string;\n  market: string;\n  strategy: string;\n  description: string;\n  pnl: number;\n  sparklineData: number[];\n  tags: string[];\n  contracts: number;\n  side: 'LONG' | 'SHORT';\n}\n\ninterface TradeSummaryProps {\n  date: string;\n  trades: TradeItem[];\n  onAddTrade?: () => void;\n}\n\n/* ---------- Sub-components ---------- */\nconst Sparkline: React.FC<{ data: number[]; lineClassName: string }> = ({\n  data,\n  lineClassName,\n}) => {\n  const width = 80;\n  const height = 24;\n  const padding = 2;\n\n  const min = Math.min(...data);\n  const max = Math.max(...data);\n  const range = max - min || 1;\n\n  const points = data\n    .map((d, i) => {\n      const x = (i / (data.length - 1)) * width;\n      const y = height - padding - ((d - min) / range) * (height - 2 * padding);\n      return `${x},${y}`;\n    })\n    .join(' ');\n\n  return (\n    <svg\n      width={width}\n      height={height}\n      viewBox={`0 0 ${width} ${height}`}\n      className={`overflow-visible ${lineClassName}`}\n    >\n      <motion.polyline\n        fill=\"none\"\n        stroke=\"currentColor\"\n        strokeWidth=\"2\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        points={points}\n        initial={{ pathLength: 0, opacity: 0 }}\n        animate={{ pathLength: 1, opacity: 1 }}\n        transition={{ duration: 1.2, ease: 'easeOut' }}\n      />\n    </svg>\n  );\n};\n\nconst FilterButton: React.FC<{ label: string }> = ({ label }) => (\n  <button className=\"border-border text-muted-foreground hover:text-foreground flex items-center gap-1.5 rounded-md border bg-transparent px-2 py-1 text-[11px] whitespace-nowrap transition-colors duration-200\">\n    {label}\n    <ChevronDown size={12} className=\"mt-0.5\" />\n  </button>\n);\n\nconst TradeCard: React.FC<{\n  trade: TradeItem;\n  isSelected: boolean;\n  onSelect: () => void;\n  isMenuOpen: boolean;\n  onMenuToggle: () => void;\n}> = ({ trade, isSelected, onSelect, isMenuOpen, onMenuToggle }) => {\n  const isPositive = trade.pnl >= 0;\n  const accentClass = isPositive ? 'text-chart-2' : 'text-destructive';\n\n  return (\n    <motion.div\n      layout\n      initial={{ opacity: 0, y: 10 }}\n      animate={{ opacity: 1, y: 0 }}\n      exit={{ opacity: 0, scale: 0.98 }}\n      whileHover={{ y: -1 }}\n      className={`group border-border relative border-b bg-transparent px-1 py-4 transition-all duration-300 last:border-0 ${isSelected ? 'bg-muted/40' : ''}`}\n    >\n      <div className=\"flex items-start gap-2.5 sm:gap-3.5\">\n        <div className=\"pt-1\">\n          <button\n            onClick={onSelect}\n            className={`flex h-4 w-4 items-center justify-center rounded border-2 transition-all duration-200 ${isSelected ? 'bg-primary border-primary' : 'border-border group-hover:border-input'}`}\n          >\n            {isSelected && <Check size={10} className=\"text-primary-foreground\" />}\n          </button>\n        </div>\n\n        <div className=\"min-w-0 flex-1\">\n          <div className=\"mb-1 flex items-start justify-between gap-2\">\n            <div className=\"truncate\">\n              <h3 className=\"text-foreground truncate text-sm font-medium tracking-tight sm:text-base\">\n                {trade.asset}\n              </h3>\n              <div className=\"text-muted-foreground mt-0 flex items-center gap-1 text-[8px] font-bold tracking-wider uppercase sm:gap-1.5 sm:text-[9px]\">\n                <span>{trade.session}</span>\n                <span>•</span>\n                <span className=\"truncate\">{trade.market}</span>\n              </div>\n            </div>\n\n            <div className=\"flex shrink-0 items-center gap-2 sm:gap-4\">\n              <div className=\"flex items-center gap-2 sm:gap-3\">\n                <div className=\"xs:block hidden\">\n                  <Sparkline\n                    data={trade.sparklineData}\n                    lineClassName={accentClass}\n                  />\n                </div>\n                <span\n                  className={`text-sm font-bold sm:text-base ${isPositive ? 'text-chart-2' : 'text-destructive'} tabular-nums`}\n                >\n                  {isPositive ? '+' : ''}$\n                  {Math.abs(trade.pnl).toLocaleString(undefined, {\n                    minimumFractionDigits: 2,\n                  })}\n                </span>\n              </div>\n              <div className=\"relative\">\n                <button\n                  title=\"more\"\n                  onClick={onMenuToggle}\n                  className={`text-muted-foreground hover:text-foreground transition-colors duration-300 ${isMenuOpen ? 'text-foreground' : ''}`}\n                >\n                  <MoreHorizontal size={16} />\n                </button>\n                <AnimatePresence>\n                  {isMenuOpen && (\n                    <motion.div\n                      initial={{ opacity: 0, scale: 0.95, y: -5 }}\n                      animate={{ opacity: 1, scale: 1, y: 0 }}\n                      exit={{ opacity: 0, scale: 0.95, y: -5 }}\n                      className=\"bg-card/95 border-border absolute top-full right-0 z-50 mt-1 w-32 origin-top-right rounded-xl border shadow-xl backdrop-blur-md\"\n                    >\n                      <div className=\"p-1.5\">\n                        <button className=\"text-muted-foreground hover:bg-muted hover:text-foreground flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-[10px] transition-colors\">\n                          <Edit2 size={12} /> Edit Trade\n                        </button>\n                        <button className=\"text-muted-foreground hover:bg-muted hover:text-foreground flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-[10px] transition-colors\">\n                          <Copy size={12} /> Duplicate\n                        </button>\n                        <div className=\"bg-border my-1 h-px\" />\n                        <button className=\"hover:bg-destructive/10 text-destructive flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-[10px] transition-colors\">\n                          <Trash2 size={12} /> Remove\n                        </button>\n                      </div>\n                    </motion.div>\n                  )}\n                </AnimatePresence>\n              </div>\n            </div>\n          </div>\n\n          <div className=\"mt-2 sm:mt-3\">\n            <h4 className=\"text-foreground text-[11px] font-medium sm:text-[12px]\">\n              {trade.strategy}\n            </h4>\n            <p className=\"text-muted-foreground mt-1 line-clamp-2 max-w-full text-[11px] leading-relaxed sm:line-clamp-none sm:text-[12px]\">\n              {trade.description}\n            </p>\n          </div>\n\n          <div className=\"mt-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between\">\n            <div className=\"flex flex-wrap gap-1.5\">\n              {trade.tags.map((tag) => (\n                <span\n                  key={tag}\n                  className=\"bg-muted border-border text-muted-foreground hover:bg-secondary hover:text-secondary-foreground cursor-default rounded-full border px-2 py-1 text-[9px] transition-colors sm:text-[10px]\"\n                >\n                  {tag}\n                </span>\n              ))}\n            </div>\n\n            <div className=\"flex items-center justify-between gap-2 sm:justify-end\">\n              <span className=\"bg-secondary border-border text-secondary-foreground rounded-full border px-2 py-1 text-[8px] font-bold tracking-widest uppercase\">\n                {trade.contracts} CTRS\n              </span>\n              <span\n                className={`rounded-full border-[0.5px] px-2 pt-1 pb-0.5 text-[8px] font-bold tracking-widest uppercase ${\n                  trade.side === 'LONG'\n                    ? 'text-chart-2 bg-chart-2/10 border-chart-2/40'\n                    : 'text-destructive bg-destructive/10 border-destructive/40'\n                }`}\n              >\n                {trade.side}\n              </span>\n            </div>\n          </div>\n        </div>\n      </div>\n    </motion.div>\n  );\n};\n\n/* ---------- Main ---------- */\nexport const TradeSummary: React.FC<TradeSummaryProps> = ({\n  date,\n  trades,\n  onAddTrade,\n}) => {\n  const DATES = ['JAN 12', 'JAN 11', 'JAN 10'];\n  const [isAddingTrade, setIsAddingTrade] = React.useState(false);\n  const [selectedIds, setSelectedIds] = React.useState<string[]>([]);\n  const [activeDate, setActiveDate] = React.useState(DATES[0]);\n  const [isDownloading, setIsDownloading] = React.useState(false);\n  const [isRefreshing, setIsRefreshing] = React.useState(false);\n  const [activeMenuId, setActiveMenuId] = React.useState<string | null>(null);\n  const [isGlobalMenuOpen, setIsGlobalMenuOpen] = React.useState(false);\n\n  const totalPnl = trades.reduce((acc, curr) => acc + curr.pnl, 0);\n  const isPositiveTotal = totalPnl >= 0;\n\n  const toggleSelect = (id: string) => {\n    setSelectedIds((prev) =>\n      prev.includes(id) ? prev.filter((i) => i !== id) : [...prev, id]\n    );\n  };\n\n  const handleRefresh = () => {\n    setIsRefreshing(true);\n    setTimeout(() => setIsRefreshing(false), 2000);\n  };\n\n  const handleDownload = () => {\n    setIsDownloading(true);\n    setTimeout(() => setIsDownloading(false), 2000);\n  };\n\n  return (\n    <div className=\"theme-injected w-full max-w-130\">\n      <div className=\"bg-card border-border flex flex-col overflow-hidden rounded-3xl border shadow-xl transition-all duration-500\">\n        {/* Top Header */}\n        <header className=\"flex flex-wrap items-center justify-between gap-2 px-3 py-3 sm:px-4\">\n          <div className=\"flex flex-wrap items-center gap-1.5 text-sm tracking-normal sm:gap-2\">\n            <span className=\"text-foreground text-xs font-medium sm:text-sm\">\n              Today\n            </span>\n            <span className=\"text-border text-xs font-bold\">/</span>\n            <span className=\"text-muted-foreground text-[8px] font-bold tracking-widest uppercase sm:text-[9px] sm:tracking-[0.2em]\">\n              {date}\n            </span>\n            <span className=\"text-border mx-0.5\">•</span>\n            <span\n              className={`text-[10px] font-bold sm:text-[11px] ${isPositiveTotal ? 'text-chart-2' : 'text-destructive'}`}\n            >\n              {isPositiveTotal ? '+' : ''}\n              {totalPnl.toLocaleString(undefined, {\n                style: 'currency',\n                currency: 'USD',\n              })}\n            </span>\n          </div>\n\n          <button\n            onClick={() => setIsAddingTrade(true)}\n            className=\"bg-primary hover:bg-primary/90 text-primary-foreground flex items-center gap-1.5 rounded-full px-3 py-2 text-[10px] font-bold shadow-md transition-all active:scale-95 sm:text-[12px]\"\n          >\n            <Plus size={14} className=\"sm:h-4 sm:w-4\" />\n            Add Trade\n          </button>\n        </header>\n\n        <AnimatePresence>\n          {isAddingTrade && (\n            <motion.div\n              initial={{ opacity: 0 }}\n              animate={{ opacity: 1 }}\n              exit={{ opacity: 0 }}\n              className=\"absolute inset-0 z-[60] flex items-center justify-center bg-black/20 px-4 backdrop-blur-sm\"\n            >\n              <motion.div\n                initial={{ opacity: 0, scale: 0.95, y: 10 }}\n                animate={{ opacity: 1, scale: 1, y: 0 }}\n                exit={{ opacity: 0, scale: 0.95, y: 10 }}\n                className=\"bg-card border-border relative w-full max-w-sm rounded-3xl border p-6 shadow-2xl\"\n              >\n                <button\n                  onClick={() => setIsAddingTrade(false)}\n                  className=\"text-muted-foreground hover:text-foreground absolute top-4 right-4\"\n                >\n                  <X size={20} />\n                </button>\n                <div className=\"mb-6\">\n                  <h3 className=\"text-foreground text-sm font-bold\">\n                    Record New Trade\n                  </h3>\n                  <p className=\"text-muted-foreground mt-1 text-[10px]\">\n                    Add manually executed trades to your journal.\n                  </p>\n                </div>\n                <div className=\"grid gap-3\">\n                  <input\n                    type=\"text\"\n                    placeholder=\"Asset (e.g. E-Mini S&P 500)\"\n                    className=\"border-input bg-transparent w-full rounded-xl border px-3 py-2 text-[11px] outline-none focus:ring-1 focus:ring-primary\"\n                  />\n                  <div className=\"grid grid-cols-2 gap-3\">\n                    <input\n                      type=\"text\"\n                      placeholder=\"Side (LONG/SHORT)\"\n                      className=\"border-input bg-transparent w-full rounded-xl border px-3 py-2 text-[11px] outline-none focus:ring-1 focus:ring-primary\"\n                    />\n                    <input\n                      type=\"text\"\n                      placeholder=\"Contracts\"\n                      className=\"border-input bg-transparent w-full rounded-xl border px-3 py-2 text-[11px] outline-none focus:ring-1 focus:ring-primary\"\n                    />\n                  </div>\n                  <textarea\n                    rows={3}\n                    placeholder=\"Brief description of the setup...\"\n                    className=\"border-input bg-transparent w-full rounded-xl border px-3 py-2 text-[11px] outline-none focus:ring-1 focus:ring-primary\"\n                  />\n                </div>\n                <button\n                  onClick={() => {\n                    setIsAddingTrade(false);\n                    onAddTrade?.();\n                  }}\n                  className=\"bg-primary text-primary-foreground mt-6 w-full rounded-xl py-2.5 text-[11px] font-bold shadow-lg transition-all hover:opacity-90 active:scale-[0.98]\"\n                >\n                  Save Entry\n                </button>\n              </motion.div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n\n        {/* Toolbar / Filters */}\n        <div className=\"bg-muted/60 flex flex-col items-stretch gap-3 rounded-t-3xl px-3 pt-4 pb-3 sm:flex-row sm:items-center sm:px-4\">\n          <div className=\"no-scrollbar flex items-center gap-2 overflow-x-auto pb-1 sm:pb-0\">\n            <FilterButton label=\"All results\" />\n            <FilterButton label=\"All strategies\" />\n            <FilterButton label=\"More\" />\n          </div>\n\n          <div className=\"group relative flex-1\">\n            <Search\n              className=\"text-muted-foreground group-focus-within:text-foreground absolute top-1/2 left-2.5 -translate-y-1/2 transition-colors\"\n              size={14}\n            />\n            <input\n              type=\"text\"\n              placeholder=\"Search trades...\"\n              className=\"bg-background border-input text-foreground placeholder:text-muted-foreground focus:border-ring w-full rounded-2xl border py-2 pr-3 pl-8 text-[12px] transition-all focus:outline-none\"\n            />\n          </div>\n        </div>\n\n        {/* Trade List Container */}\n        <div className=\"bg-muted/60 min-h-87.5 flex-1 overflow-y-auto rounded-b-3xl px-3 pb-2 sm:min-h-100 sm:px-4\">\n          <AnimatePresence mode=\"popLayout\">\n            {trades.map((trade) => (\n              <TradeCard\n                key={trade.id}\n                trade={trade}\n                isSelected={selectedIds.includes(trade.id)}\n                onSelect={() => toggleSelect(trade.id)}\n                isMenuOpen={activeMenuId === trade.id}\n                onMenuToggle={() =>\n                  setActiveMenuId(activeMenuId === trade.id ? null : trade.id)\n                }\n              />\n            ))}\n          </AnimatePresence>\n        </div>\n\n        {/* Footer Navigation */}\n        <footer className=\"bg-card flex flex-col items-center justify-between gap-4 px-3 py-4 sm:flex-row sm:px-4\">\n          <div className=\"flex w-full items-center justify-center gap-4 sm:w-auto sm:justify-start\">\n            <div className=\"relative\">\n              <button\n                title=\"options\"\n                onClick={() => setIsGlobalMenuOpen(!isGlobalMenuOpen)}\n                className={`flex h-8 w-8 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-muted hover:text-foreground ${isGlobalMenuOpen ? 'bg-muted text-foreground' : ''}`}\n              >\n                <MoreVertical size={18} />\n              </button>\n              <AnimatePresence>\n                {isGlobalMenuOpen && (\n                  <motion.div\n                    initial={{ opacity: 0, scale: 0.95, y: 5 }}\n                    animate={{ opacity: 1, scale: 1, y: 0 }}\n                    exit={{ opacity: 0, scale: 0.95, y: 5 }}\n                    className=\"bg-card/95 border-border absolute bottom-full left-0 z-50 mb-1 w-36 origin-bottom-left rounded-xl border shadow-xl backdrop-blur-md\"\n                  >\n                    <div className=\"p-1.5\">\n                      <button className=\"text-muted-foreground hover:bg-muted hover:text-foreground flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-[10px] transition-colors\">\n                        Analytics Settings\n                      </button>\n                      <button className=\"text-muted-foreground hover:bg-muted hover:text-foreground flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-[10px] transition-colors\">\n                        Export Config\n                      </button>\n                      <div className=\"bg-border my-1 h-px\" />\n                      <button className=\"text-muted-foreground hover:bg-muted hover:text-foreground flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-[10px] transition-colors\">\n                        History Labels\n                      </button>\n                    </div>\n                  </motion.div>\n                )}\n              </AnimatePresence>\n            </div>\n            <div className=\"bg-border h-4 w-px\" />\n            <button\n              title=\"download\"\n              onClick={handleDownload}\n              disabled={isDownloading}\n              className=\"flex h-8 w-8 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-muted hover:text-foreground\"\n            >\n              {isDownloading ? (\n                <Loader2 size={18} className=\"text-primary animate-spin\" />\n              ) : (\n                <Download size={18} />\n              )}\n            </button>\n            <button\n              title=\"refresh\"\n              onClick={handleRefresh}\n              disabled={isRefreshing}\n              className=\"flex h-8 w-8 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-muted hover:text-foreground\"\n            >\n              <RefreshCcw\n                size={18}\n                className={isRefreshing ? 'text-primary animate-spin' : ''}\n              />\n            </button>\n          </div>\n\n          <div className=\"flex w-full items-center justify-center gap-3 sm:w-auto sm:justify-end\">\n            <button\n              title=\"backward\"\n              onClick={() => {\n                const currentIndex = DATES.indexOf(activeDate);\n                if (currentIndex > 0) setActiveDate(DATES[currentIndex - 1]);\n              }}\n              disabled={DATES.indexOf(activeDate) === 0}\n              className={`transition-colors ${DATES.indexOf(activeDate) === 0 ? 'text-border cursor-not-allowed' : 'text-muted-foreground hover:text-foreground'}`}\n            >\n              <ChevronLeft size={18} />\n            </button>\n            <div className=\"flex items-center gap-2 text-[9px] font-bold tracking-widest uppercase sm:gap-3 sm:text-[10px]\">\n              {DATES.map((day) => (\n                <button\n                  key={day}\n                  onClick={() => setActiveDate(day)}\n                  className={`relative flex px-2 py-2 transition-colors ${activeDate === day ? 'text-primary' : 'text-muted-foreground hover:text-foreground'}`}\n                >\n                  {activeDate === day && (\n                    <motion.div\n                      layoutId=\"activeDayGlowBase\"\n                      className=\"bg-primary/10 border-primary/40 absolute inset-0 rounded-md border\"\n                      transition={{ type: 'spring', bounce: 0.2, duration: 0.6 }}\n                    />\n                  )}\n                  <span className=\"relative z-10\">{day}</span>\n                </button>\n              ))}\n            </div>\n            <button\n              title=\"forward\"\n              onClick={() => {\n                const currentIndex = DATES.indexOf(activeDate);\n                if (currentIndex < DATES.length - 1)\n                  setActiveDate(DATES[currentIndex + 1]);\n              }}\n              disabled={DATES.indexOf(activeDate) === DATES.length - 1}\n              className={`transition-colors ${DATES.indexOf(activeDate) === DATES.length - 1 ? 'text-border cursor-not-allowed' : 'text-muted-foreground hover:text-foreground'}`}\n            >\n              <ChevronRight size={18} />\n            </button>\n          </div>\n        </footer>\n      </div>\n    </div>\n  );\n};\n"
    }
  ]
}
