{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ds-bullet-chart",
  "description": "Compact bullet chart with qualitative range bands, value bar, and target marker.",
  "dependencies": [
    "class-variance-authority"
  ],
  "registryDependencies": [
    "@lema-ds/skeleton",
    "@lema-ds/tooltip",
    "@lema-ds/ui-i18n",
    "@lema-ds/format-utils",
    "@lema-ds/ds-locale-provider",
    "@lema-ds/tokens"
  ],
  "files": [
    {
      "path": "components/ds/ds-bullet-chart.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cva } from \"class-variance-authority\"\nimport { cn } from \"@/lib/utils\"\nimport { Skeleton } from \"@/components/ui/skeleton\"\nimport { UI_I18N, type UILocale } from \"@/lib/ui-i18n\"\nimport { useUILocale } from \"@/components/ui/ds-locale-provider\"\nimport { formatChartValue, type FormatPreset } from \"@/lib/format-utils\"\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipProvider,\n  TooltipTrigger,\n} from \"@/components/ui/tooltip\"\n\n// ── Types ──────────────────────────────────────────────────────────────────\n\nexport type BulletChartSize = \"sm\" | \"md\" | \"lg\"\n\nexport interface BulletChartProps extends React.HTMLAttributes<HTMLDivElement> {\n  /** Metric label */\n  label: string\n  /** The current measured value */\n  value: number\n  /** The target/goal value — rendered as a vertical tick */\n  target?: number\n  /**\n   * Qualitative range thresholds [poor, ok, good].\n   * Rendered as background bands from low to high risk.\n   * If omitted, no range bands are shown.\n   */\n  ranges?: [number, number, number]\n  /** Axis maximum — defaults to max(value, target, ranges[-1]) * 1.1 */\n  max?: number\n  size?: BulletChartSize\n  valueFormatter?: (v: number) => string\n  format?: FormatPreset\n  decimals?: number\n  currency?: string\n  abbreviate?: boolean\n  loading?: boolean\n  locale?: UILocale\n}\n\n// ── Variants ───────────────────────────────────────────────────────────────\n\nexport const bulletChartContainerVariants = cva(\"w-full\", {\n  variants: {\n    size: {\n      sm: \"gap-1\",\n      md: \"gap-1.5\",\n      lg: \"gap-2\",\n    },\n  },\n  defaultVariants: { size: \"md\" },\n})\n\nexport const bulletChartLabelVariants = cva(\n  \"shrink-0 truncate font-medium text-muted-foreground\",\n  {\n    variants: {\n      size: {\n        sm: \"w-24 text-xs\",\n        md: \"w-28 text-sm\",\n        lg: \"w-32 text-base\",\n      },\n    },\n    defaultVariants: { size: \"md\" },\n  }\n)\n\nexport const bulletChartValueVariants = cva(\n  \"shrink-0 text-right font-semibold text-foreground tabular-nums\",\n  {\n    variants: {\n      size: {\n        sm: \"w-12 text-xs\",\n        md: \"w-14 text-sm\",\n        lg: \"w-16 text-base\",\n      },\n    },\n    defaultVariants: { size: \"md\" },\n  }\n)\n\nexport const bulletChartTrackVariants = cva(\n  \"relative flex-1 overflow-hidden rounded-sm bg-muted\",\n  {\n    variants: {\n      size: {\n        sm: \"h-2\",\n        md: \"h-3\",\n        lg: \"h-4\",\n      },\n    },\n    defaultVariants: { size: \"md\" },\n  }\n)\n\n// ── Skeleton dims ─────────────────────────────────────────────────────────\n\nconst skeletonDims: Record<\n  BulletChartSize,\n  { label: string; value: string; track: string }\n> = {\n  sm: { label: \"h-3 w-20\", value: \"h-3 w-10\", track: \"h-2\" },\n  md: { label: \"h-4 w-24\", value: \"h-4 w-12\", track: \"h-3\" },\n  lg: { label: \"h-5 w-28\", value: \"h-5 w-14\", track: \"h-4\" },\n}\n\n// ── Risk range colors (4 bands from worst to best) ────────────────────────\n\nconst RANGE_COLORS = [\n  \"bg-risk-1\", // lowest threshold → worst performance\n  \"bg-risk-2\",\n  \"bg-risk-3\",\n  \"bg-risk-4\", // upper area → best performance\n]\n\n// ── BulletChart ────────────────────────────────────────────────────────────\n\nexport function BulletChart({\n  label,\n  value,\n  target,\n  ranges,\n  max: maxProp,\n  size = \"md\",\n  valueFormatter,\n  format,\n  decimals = 0,\n  currency = \"USD\",\n  abbreviate = false,\n  loading = false,\n  locale: localeProp,\n  className,\n  ...props\n}: BulletChartProps) {\n  const locale = useUILocale(localeProp)\n  const formatValue = React.useCallback(\n    (v: number) => {\n      if (valueFormatter) return valueFormatter(v)\n      return formatChartValue(v, {\n        format,\n        decimals,\n        locale,\n        currency,\n        abbreviate,\n      })\n    },\n    [valueFormatter, format, decimals, locale, currency, abbreviate]\n  )\n\n  // ── Loading ─────────────────────────────────────────────────────────────\n\n  if (loading) {\n    const d = skeletonDims[size]\n    return (\n      <div\n        className={cn(\"flex items-center gap-2\", className)}\n        aria-hidden=\"true\"\n        {...props}\n      >\n        <Skeleton className={d.label} />\n        <Skeleton className={cn(\"flex-1 rounded-sm\", d.track)} />\n        <Skeleton className={d.value} />\n      </div>\n    )\n  }\n\n  // ── Compute ──────────────────────────────────────────────────────────────\n\n  const maxCandidate = Math.max(\n    value,\n    target ?? 0,\n    ranges ? (ranges[2] ?? 0) : 0\n  )\n  const axisMax = (maxProp ?? maxCandidate * 1.15) || 1\n  const valuePct = Math.min(100, (value / axisMax) * 100)\n  const targetPct =\n    target !== undefined ? Math.min(100, (target / axisMax) * 100) : null\n\n  // ── Range bands ──────────────────────────────────────────────────────────\n\n  const rangeBands = ranges\n    ? [\n        { from: 0, to: ranges[0]!, colorClass: RANGE_COLORS[0]! },\n        { from: ranges[0]!, to: ranges[1]!, colorClass: RANGE_COLORS[1]! },\n        { from: ranges[1]!, to: ranges[2]!, colorClass: RANGE_COLORS[2]! },\n        { from: ranges[2]!, to: axisMax, colorClass: RANGE_COLORS[3]! },\n      ]\n    : []\n\n  const targetLabel =\n    target !== undefined\n      ? `${label}: ${formatValue(value)} / Target: ${formatValue(target)}`\n      : `${label}: ${formatValue(value)}`\n\n  return (\n    <TooltipProvider delayDuration={100}>\n      <div\n        className={cn(\n          \"flex items-center gap-2\",\n          bulletChartContainerVariants({ size }),\n          className\n        )}\n        role=\"meter\"\n        aria-valuenow={Math.round(value)}\n        aria-valuemin={0}\n        aria-valuemax={Math.round(axisMax)}\n        aria-label={targetLabel}\n        {...props}\n      >\n        {/* Label */}\n        <span className={bulletChartLabelVariants({ size })}>{label}</span>\n\n        {/* Track */}\n        <Tooltip>\n          <TooltipTrigger asChild>\n            <div className={cn(bulletChartTrackVariants({ size }))}>\n              {/* Range bands */}\n              {rangeBands.map((band, i) => {\n                const leftPct = (band.from / axisMax) * 100\n                const widthPct = ((band.to - band.from) / axisMax) * 100\n                return (\n                  <div\n                    key={i}\n                    className={cn(\n                      \"absolute inset-y-0\",\n                      band.colorClass,\n                      \"opacity-40\"\n                    )}\n                    style={{\n                      left: `${leftPct}%`,\n                      width: `${widthPct}%`,\n                    }}\n                  />\n                )\n              })}\n\n              {/* Value bar */}\n              <div\n                className=\"absolute inset-y-0 left-0 rounded-sm bg-primary transition-all duration-500\"\n                style={{ width: `${valuePct}%` }}\n              />\n\n              {/* Target marker */}\n              {targetPct !== null && (\n                <div\n                  className=\"absolute -inset-y-0.5 w-0.5 rounded-full bg-foreground\"\n                  style={{ left: `${targetPct}%` }}\n                  aria-hidden=\"true\"\n                />\n              )}\n            </div>\n          </TooltipTrigger>\n          <TooltipContent>\n            <div className=\"flex flex-col gap-0.5 text-xs\">\n              <span className=\"font-medium\">{label}</span>\n              <span>\n                {UI_I18N[locale].riskLevelBar?.value ?? \"Value\"}:{\" \"}\n                <span className=\"font-semibold tabular-nums\">\n                  {formatValue(value)}\n                </span>\n              </span>\n              {target !== undefined && (\n                <span>\n                  Target:{\" \"}\n                  <span className=\"font-semibold tabular-nums\">\n                    {formatValue(target)}\n                  </span>\n                </span>\n              )}\n            </div>\n          </TooltipContent>\n        </Tooltip>\n\n        {/* Value */}\n        <span className={bulletChartValueVariants({ size })}>\n          {formatValue(value)}\n        </span>\n      </div>\n    </TooltipProvider>\n  )\n}\n\n// ── BulletChartGroup ───────────────────────────────────────────────────────\n\nexport interface BulletChartGroupProps extends React.HTMLAttributes<HTMLDivElement> {\n  items: BulletChartProps[]\n  size?: BulletChartSize\n  loading?: boolean\n}\n\nexport function BulletChartGroup({\n  items,\n  size = \"md\",\n  loading = false,\n  className,\n  ...props\n}: BulletChartGroupProps) {\n  return (\n    <div className={cn(\"flex flex-col gap-3\", className)} {...props}>\n      {items.map((item, i) => (\n        <BulletChart key={i} {...item} size={size} loading={loading} />\n      ))}\n    </div>\n  )\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}
