{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-card-stat-heatbar",
  "title": "Card Stat Heatbar",
  "description": "A statistical card with a segmented heatbar visualization for multi-zone metric display.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react"
  ],
  "registryDependencies": [
    "@lema-ds/card-stat-shared",
    "@lema-ds/card",
    "@lema-ds/progress",
    "@lema-ds/skeleton",
    "@lema-ds/badge",
    "@lema-ds/tooltip",
    "@lema-ds/ui-i18n",
    "@lema-ds/ds-locale-provider"
  ],
  "files": [
    {
      "path": "components/ds/ds-card-stat-heatbar.tsx",
      "content": "import * as React from \"react\"\nimport { cva } from \"class-variance-authority\"\n\nimport { cn } from \"@/lib/utils\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useOptionalUILocale } from \"@/components/ui/ds-locale-provider\"\nimport { Badge } from \"@/components/ui/badge\"\nimport { Card, CardAction, CardContent, CardHeader } from \"@/components/ui/card\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipProvider,\n  TooltipTrigger,\n} from \"@/components/ui/tooltip\"\n\nimport {\n  type CardStatSize,\n  type FormatOptions,\n  applyFormat,\n  cardStatLabelVariants,\n  cardStatValueVariants,\n  cardStatDescriptionVariants,\n  cardStatHeaderIconVariants,\n  cardStatContentGapVariants,\n  cardStatBadgePaddingVariants,\n} from \"@/lib/card-stats-shared\"\n\n// ── Types ──\nexport interface CardStatHeatbarZone {\n  label: string\n  color: string\n  max: number\n}\n\nexport interface CardStatHeatbarProps extends FormatOptions {\n  label: string\n  value: number\n  min?: number\n  max?: number\n  description?: string\n  zones?: CardStatHeatbarZone[]\n  icon?: React.ElementType\n  size?: CardStatSize\n  className?: string\n  loading?: boolean\n  empty?: boolean\n  locale?: UILocale\n}\n\n// ── Variants ──\nexport const cardStatTrackHVariants = cva(\"\", {\n  variants: {\n    size: {\n      sm: \"h-2\",\n      md: \"h-3\",\n      lg: \"h-4\",\n    },\n  },\n  defaultVariants: { size: \"sm\" },\n})\n\nexport const cardStatMarkerTopVariants = cva(\"\", {\n  variants: {\n    size: {\n      sm: \"top-1.5\",\n      md: \"top-2.5\",\n      lg: \"top-3\",\n    },\n  },\n  defaultVariants: { size: \"sm\" },\n})\n\n// ── Helpers ──\nconst DEFAULT_HEATBAR_ZONES: CardStatHeatbarZone[] = [\n  { label: \"Poor\", color: \"var(--color-risk-1)\", max: 25 },\n  { label: \"Fair\", color: \"var(--color-risk-2)\", max: 50 },\n  { label: \"Good\", color: \"var(--color-risk-3)\", max: 75 },\n  { label: \"Excellent\", color: \"var(--color-risk-4)\", max: 100 },\n]\n\nexport function CardStatHeatbar({\n  label,\n  value,\n  min = 0,\n  max = 100,\n  description,\n  zones: zonesProp,\n  icon: Icon,\n  size = \"sm\",\n  className,\n  loading,\n  empty,\n  locale: localeProp,\n  ...fmt\n}: CardStatHeatbarProps) {\n  const locale = useOptionalUILocale(localeProp)\n  const zones =\n    zonesProp ??\n    (locale\n      ? [\n          {\n            label: UI_I18N[locale].cardStatGauge.poor,\n            color: \"var(--color-risk-1)\",\n            max: 25,\n          },\n          {\n            label: UI_I18N[locale].cardStatGauge.fair,\n            color: \"var(--color-risk-2)\",\n            max: 50,\n          },\n          {\n            label: UI_I18N[locale].cardStatGauge.good,\n            color: \"var(--color-risk-3)\",\n            max: 75,\n          },\n          {\n            label: UI_I18N[locale].cardStatGauge.excellent,\n            color: \"var(--color-risk-4)\",\n            max: 100,\n          },\n        ]\n      : DEFAULT_HEATBAR_ZONES)\n  if (loading) {\n    return (\n      <Card size=\"sm\" className={className} data-slot=\"card-stat-heatbar\">\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={cn(\"flex flex-col\", cardStatContentGapVariants({ size }))}\n          data-slot=\"card-stat-heatbar-skeleton\"\n        >\n          <div className=\"flex items-baseline justify-between\">\n            <Skeleton className=\"h-7 w-28\" />\n            <Skeleton className=\"h-5 w-20 rounded-full\" />\n          </div>\n          <div className=\"flex flex-col gap-2 pb-6\">\n            <Skeleton\n              className={cn(cardStatTrackHVariants({ size }), \"rounded-full\")}\n            />\n            <div className=\"flex justify-between px-0.5\">\n              {[...Array(4)].map((_, i) => (\n                <Skeleton key={i} className=\"h-2 w-8 rounded\" />\n              ))}\n            </div>\n          </div>\n          <Skeleton className=\"h-3 w-40 rounded-md\" />\n        </CardContent>\n      </Card>\n    )\n  }\n\n  if (empty) {\n    return (\n      <Card size=\"sm\" className={className} data-slot=\"card-stat-heatbar\">\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={cn(\"flex flex-col\", cardStatContentGapVariants({ size }))}\n          data-slot=\"card-stat-heatbar-empty\"\n        >\n          <div className=\"flex items-baseline justify-between\">\n            <p\n              className={cn(\n                cardStatValueVariants({ size }),\n                \"text-muted-foreground/25\"\n              )}\n            >\n              —\n            </p>\n            <Badge\n              variant=\"outline\"\n              className={cn(\n                \"text-muted-foreground/60\",\n                cardStatBadgePaddingVariants({ size }),\n                cardStatDescriptionVariants({ size })\n              )}\n            >\n              {locale ? UI_I18N[locale].cardStatGauge.pending : \"Pending\"}\n            </Badge>\n          </div>\n          <div className=\"relative pb-10\">\n            <div\n              className={cn(\n                \"flex overflow-hidden rounded-full\",\n                cardStatTrackHVariants({ size })\n              )}\n            >\n              {zones.map((zone, i) => {\n                const prevMax = i === 0 ? 0 : zones[i - 1].max\n                const segW = zone.max - prevMax\n                return (\n                  <div\n                    key={zone.label}\n                    style={{ width: `${segW}%`, backgroundColor: zone.color }}\n                    className={cn(\n                      \"opacity-15\",\n                      i === 0 && \"rounded-l-full\",\n                      i === zones.length - 1 && \"rounded-r-full\"\n                    )}\n                  />\n                )\n              })}\n            </div>\n            <div className=\"absolute top-8 flex w-full justify-between px-0.5\">\n              {zones.map((z) => (\n                <span\n                  key={z.label}\n                  className={cn(\n                    \"leading-none text-muted-foreground/40\",\n                    cardStatDescriptionVariants({ size })\n                  )}\n                >\n                  {z.label}\n                </span>\n              ))}\n            </div>\n          </div>\n          {description && (\n            <p\n              className={cn(\n                \"text-muted-foreground/40\",\n                cardStatDescriptionVariants({ size })\n              )}\n            >\n              {description}\n            </p>\n          )}\n        </CardContent>\n      </Card>\n    )\n  }\n\n  const display = applyFormat(value, { locale, ...fmt })\n  const pct = Math.min(100, Math.max(0, ((value - min) / (max - min)) * 100))\n  const activeZone = zones.find((z) => pct <= z.max) ?? zones[zones.length - 1]\n\n  return (\n    <Card size=\"sm\" className={className} data-slot=\"card-stat-heatbar\">\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={cn(\"flex flex-col\", cardStatContentGapVariants({ size }))}\n        data-slot=\"card-stat-heatbar\"\n      >\n        <div className=\"flex items-baseline justify-between\">\n          <p className={cardStatValueVariants({ size })}>{display}</p>\n          <span\n            className={cn(\n              \"rounded-full font-semibold\",\n              cardStatBadgePaddingVariants({ size }),\n              cardStatDescriptionVariants({ size })\n            )}\n            style={{ backgroundColor: activeZone.color, color: \"white\" }}\n            aria-hidden\n          >\n            {activeZone.label}\n          </span>\n        </div>\n\n        <TooltipProvider>\n          <Tooltip>\n            <TooltipTrigger asChild>\n              <div className=\"relative cursor-default pb-10 select-none\">\n                <div\n                  role=\"progressbar\"\n                  aria-valuenow={value}\n                  aria-valuemin={min}\n                  aria-valuemax={max}\n                  aria-label={label}\n                  className={cn(\n                    \"flex overflow-hidden rounded-full\",\n                    cardStatTrackHVariants({ size })\n                  )}\n                >\n                  {zones.map((zone, i) => {\n                    const prevMax = i === 0 ? 0 : zones[i - 1].max\n                    const segW = zone.max - prevMax\n                    return (\n                      <div\n                        key={zone.label}\n                        style={{\n                          width: `${segW}%`,\n                          backgroundColor: zone.color,\n                        }}\n                        className={cn(\n                          \"opacity-80\",\n                          i === 0 && \"rounded-l-full\",\n                          i === zones.length - 1 && \"rounded-r-full\"\n                        )}\n                      />\n                    )\n                  })}\n                </div>\n\n                <div\n                  className={cn(\n                    \"absolute -translate-x-1/2 pt-0.5\",\n                    cardStatMarkerTopVariants({ size })\n                  )}\n                  style={{ left: `${pct}%` }}\n                >\n                  <svg width=\"10\" height=\"6\" viewBox=\"0 0 10 6\" aria-hidden>\n                    <polygon\n                      points=\"5,0 10,6 0,6\"\n                      style={{ fill: activeZone.color }}\n                    />\n                  </svg>\n                </div>\n\n                <div className=\"absolute top-8 flex w-full justify-between px-0.5\">\n                  {zones.map((z) => (\n                    <span\n                      key={z.label}\n                      className={cn(\n                        \"leading-none text-muted-foreground\",\n                        cardStatDescriptionVariants({ size })\n                      )}\n                    >\n                      {z.label}\n                    </span>\n                  ))}\n                </div>\n              </div>\n            </TooltipTrigger>\n            <TooltipContent side=\"top\">\n              {display} — {activeZone.label}\n            </TooltipContent>\n          </Tooltip>\n        </TooltipProvider>\n\n        {description && (\n          <p\n            className={cn(\n              \"text-muted-foreground\",\n              cardStatDescriptionVariants({ size })\n            )}\n          >\n            {description}\n          </p>\n        )}\n      </CardContent>\n    </Card>\n  )\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
