{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-card-stat-sparkline",
  "title": "Card Stat Sparkline",
  "description": "A statistical card with an inline sparkline chart for visual trend representation.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "@lema-ds/card-stat-shared",
    "@lema-ds/card",
    "@lema-ds/skeleton",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider"
  ],
  "files": [
    {
      "path": "components/ds/ds-card-stat-sparkline.tsx",
      "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useOptionalUILocale } from \"@/components/ui/ds-locale-provider\"\nimport { Card, CardAction, CardContent, CardHeader } from \"@/components/ui/card\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\n\nimport {\n  type CardStatTrend,\n  type CardStatSize,\n  type FormatOptions,\n  applyFormat,\n  resolveTrend,\n  TrendBadge,\n  cardStatLabelVariants,\n  cardStatValueVariants,\n  cardStatDescriptionVariants,\n  cardStatHeaderIconVariants,\n} from \"@/lib/card-stats-shared\"\n\nfunction toSvgPts(\n  data: number[],\n  w: number,\n  h: number,\n  pad = 4\n): [number, number][] {\n  if (data.length < 2) return []\n  const min = Math.min(...data)\n  const max = Math.max(...data)\n  const range = max - min || 1\n  return data.map((v, i) => [\n    pad + (i / (data.length - 1)) * (w - pad * 2),\n    pad + (h - pad * 2) - ((v - min) / range) * (h - pad * 2),\n  ])\n}\n\nfunction catmullRom(pts: [number, number][], tension = 0.4): string {\n  if (pts.length < 2) return \"\"\n  if (pts.length === 2)\n    return `M ${pts[0][0]} ${pts[0][1]} L ${pts[1][0]} ${pts[1][1]}`\n  let d = `M ${pts[0][0]} ${pts[0][1]}`\n  for (let i = 0; i < pts.length - 1; i++) {\n    const p0 = pts[Math.max(0, i - 1)]\n    const p1 = pts[i]\n    const p2 = pts[i + 1]\n    const p3 = pts[Math.min(pts.length - 1, i + 2)]\n    const cp1x = p1[0] + (p2[0] - p0[0]) * tension\n    const cp1y = p1[1] + (p2[1] - p0[1]) * tension\n    const cp2x = p2[0] - (p3[0] - p1[0]) * tension\n    const cp2y = p2[1] - (p3[1] - p1[1]) * tension\n    d += ` C ${cp1x.toFixed(1)} ${cp1y.toFixed(1)} ${cp2x.toFixed(1)} ${cp2y.toFixed(1)} ${p2[0].toFixed(1)} ${p2[1].toFixed(1)}`\n  }\n  return d\n}\n\nfunction SparklineSvg({\n  data,\n  width = 120,\n  height = 44,\n  trend,\n}: {\n  data: number[]\n  width?: number\n  height?: number\n  trend?: CardStatTrend | boolean\n}) {\n  const id = React.useId()\n  const dir = resolveTrend(trend)\n  const stroke =\n    dir === \"up\"\n      ? \"var(--color-success)\"\n      : dir === \"down\"\n        ? \"var(--color-destructive)\"\n        : \"currentColor\"\n\n  const pts = toSvgPts(data, width, height)\n  const line = catmullRom(pts)\n  const last = pts[pts.length - 1]\n  const first = pts[0]\n  const area =\n    pts.length >= 2\n      ? `${line} L ${last[0]} ${height} L ${first[0]} ${height} Z`\n      : \"\"\n\n  return (\n    <svg\n      viewBox={`0 0 ${width} ${height}`}\n      className=\"shrink-0 overflow-visible\"\n      aria-hidden\n    >\n      <defs>\n        <linearGradient id={`sg-${id}`} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n          <stop offset=\"0%\" style={{ stopColor: stroke }} stopOpacity=\"0.22\" />\n          <stop offset=\"100%\" style={{ stopColor: stroke }} stopOpacity=\"0\" />\n        </linearGradient>\n      </defs>\n      {area && <path d={area} fill={`url(#sg-${id})`} />}\n      {line && (\n        <path\n          d={line}\n          fill=\"none\"\n          style={{ stroke }}\n          strokeWidth=\"1.75\"\n          strokeLinecap=\"round\"\n          strokeLinejoin=\"round\"\n        />\n      )}\n      {last && (\n        <circle cx={last[0]} cy={last[1]} r=\"2.5\" style={{ fill: stroke }} />\n      )}\n    </svg>\n  )\n}\n\nfunction FlatSparklineSvg({\n  width = 120,\n  height = 44,\n}: {\n  width?: number\n  height?: number\n}) {\n  return (\n    <svg\n      viewBox={`0 0 ${width} ${height}`}\n      className=\"shrink-0 overflow-visible\"\n      aria-hidden\n    >\n      <line\n        x1=\"4\"\n        y1={height / 2}\n        x2={width - 4}\n        y2={height / 2}\n        stroke=\"currentColor\"\n        className=\"text-muted-foreground/25\"\n        strokeWidth=\"1.5\"\n        strokeLinecap=\"round\"\n        strokeDasharray=\"6 4\"\n      />\n    </svg>\n  )\n}\n\nexport interface CardStatSparklineProps extends FormatOptions {\n  label: string\n  value: string | number\n  data?: number[]\n  trend?: CardStatTrend | boolean\n  trendValue?: string\n  description?: string\n  icon?: React.ElementType\n  size?: CardStatSize\n  className?: string\n  loading?: boolean\n  empty?: boolean\n  locale?: UILocale\n}\n\nexport function CardStatSparkline({\n  label,\n  value,\n  data = [],\n  trend,\n  trendValue,\n  description,\n  icon: Icon,\n  size = \"sm\",\n  className,\n  loading,\n  empty,\n  locale: localeProp,\n  ...fmt\n}: CardStatSparklineProps) {\n  const locale = useOptionalUILocale(localeProp)\n  const sparklineW = size === \"sm\" ? 90 : size === \"lg\" ? 150 : 120\n  const sparklineH = size === \"sm\" ? 32 : size === \"lg\" ? 56 : 44\n\n  if (loading) {\n    return (\n      <Card size=\"sm\" className={className} data-slot=\"card-stat-sparkline\">\n        <CardHeader className=\"flex flex-row items-center justify-between\">\n          <Skeleton className=\"h-3 w-28 rounded-md\" />\n          <Skeleton\n            className={cn(cardStatHeaderIconVariants({ size }), \"rounded-md\")}\n          />\n        </CardHeader>\n        <CardContent\n          className=\"flex items-end justify-between gap-4\"\n          data-slot=\"card-stat-sparkline-skeleton\"\n        >\n          <div className=\"flex flex-col gap-1.5\">\n            <Skeleton className=\"h-7 w-28\" />\n            <Skeleton className=\"h-5 w-24 rounded-full\" />\n          </div>\n          <Skeleton\n            className=\"rounded-xl\"\n            style={{ height: sparklineH, width: sparklineW }}\n          />\n        </CardContent>\n      </Card>\n    )\n  }\n\n  if (empty) {\n    return (\n      <Card size=\"sm\" className={className} data-slot=\"card-stat-sparkline\">\n        <CardHeader className=\"flex flex-row items-center justify-between\">\n          <span\n            className={cn(\n              \"truncate text-muted-foreground\",\n              cardStatLabelVariants({ size })\n            )}\n          >\n            {label}\n          </span>\n          {Icon && (\n            <CardAction className=\"text-muted-foreground\">\n              <Icon\n                className={cardStatHeaderIconVariants({ size })}\n                aria-hidden\n              />\n            </CardAction>\n          )}\n        </CardHeader>\n        <CardContent\n          className=\"flex items-end justify-between gap-4\"\n          data-slot=\"card-stat-sparkline\"\n        >\n          <div className=\"flex flex-col gap-1.5\">\n            <p\n              className={cn(\n                cardStatValueVariants({ size }),\n                \"text-muted-foreground/25\"\n              )}\n            >\n              —\n            </p>\n            <p\n              className={cn(\n                \"text-muted-foreground/40\",\n                cardStatDescriptionVariants({ size })\n              )}\n            >\n              {locale\n                ? UI_I18N[locale].cardStatSparkline.noHistory\n                : \"No history yet\"}\n            </p>\n          </div>\n          <FlatSparklineSvg width={sparklineW} height={sparklineH} />\n        </CardContent>\n      </Card>\n    )\n  }\n\n  const display = applyFormat(value, { locale, ...fmt })\n  const trendDir = resolveTrend(trend)\n\n  return (\n    <Card size=\"sm\" className={className} data-slot=\"card-stat-sparkline\">\n      <CardHeader className=\"flex flex-row items-center justify-between\">\n        <span\n          className={cn(\n            \"truncate text-muted-foreground\",\n            cardStatLabelVariants({ size })\n          )}\n        >\n          {label}\n        </span>\n        {Icon && (\n          <CardAction className=\"text-muted-foreground\">\n            <Icon\n              className={cardStatHeaderIconVariants({ size })}\n              aria-hidden\n            />\n          </CardAction>\n        )}\n      </CardHeader>\n      <CardContent className=\"flex items-end justify-between gap-4\">\n        <div className=\"flex flex-col gap-1.5\">\n          <p className={cardStatValueVariants({ size })}>{display}</p>\n          {trendDir && trendValue ? (\n            <TrendBadge trend={trendDir} value={trendValue} size={size} />\n          ) : description ? (\n            <p\n              className={cn(\n                \"text-muted-foreground\",\n                cardStatDescriptionVariants({ size })\n              )}\n            >\n              {description}\n            </p>\n          ) : null}\n        </div>\n        {data.length >= 2 && (\n          <SparklineSvg\n            data={data}\n            trend={trend}\n            width={sparklineW}\n            height={sparklineH}\n          />\n        )}\n      </CardContent>\n    </Card>\n  )\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
