{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "insights",
  "title": "Insights",
  "description": "Primitives for insights: positive, negative, neutral and anomaly kinds, each named by a coloured word, sentences with their metrics picked out in colour, and a \"why\" line of drivers.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/insights.tsx",
      "content": "'use client'\n\nimport {\n  StatusLabel,\n  type StatusLabelProps,\n  type StatusTone,\n  statusToneClasses,\n} from '@/registry/components/dashboardblocks/status-label'\nimport type { ReactNode } from 'react'\n\nimport { cn } from '@/lib/utils'\n\ntype InsightKind = 'positive' | 'negative' | 'neutral' | 'anomaly'\n\ntype InsightTone = 'positive' | 'negative' | 'neutral'\n\ninterface InsightKindConfig {\n  fill: string\n  label: string\n  tone: StatusTone\n}\n\nconst insightKindConfig: Record<InsightKind, InsightKindConfig> = {\n  anomaly: {\n    fill: 'var(--color-orange-500)',\n    label: 'Anomaly',\n    tone: 'warning',\n  },\n  negative: {\n    fill: 'var(--color-red-600)',\n    label: 'Negative',\n    tone: 'bad',\n  },\n  neutral: {\n    fill: 'var(--color-muted-foreground)',\n    label: 'Neutral',\n    tone: 'neutral',\n  },\n  positive: {\n    fill: 'var(--color-emerald-600)',\n    label: 'Positive',\n    tone: 'good',\n  },\n}\n\nconst toneClassNames: Record<InsightTone, string> = {\n  negative: statusToneClasses.bad,\n  neutral: 'text-foreground',\n  positive: statusToneClasses.good,\n}\n\nfunction InsightLabel({\n  className,\n  kind,\n  label,\n  variant,\n}: {\n  className?: string\n  kind: InsightKind\n  label?: string\n  variant?: StatusLabelProps['variant']\n}) {\n  const config = insightKindConfig[kind]\n  return (\n    <StatusLabel className={className} tone={config.tone} variant={variant}>\n      {label ?? config.label}\n    </StatusLabel>\n  )\n}\n\ninterface InsightMetric {\n  text: string\n  /** @default 'neutral' */\n  tone?: InsightTone\n}\n\ntype InsightSegment = string | InsightMetric\n\nfunction InsightHighlight({\n  children,\n  className,\n  tone = 'neutral',\n}: {\n  children: ReactNode\n  className?: string\n  tone?: InsightTone\n}) {\n  return (\n    <strong className={cn('font-medium tabular-nums', toneClassNames[tone], className)}>\n      {children}\n    </strong>\n  )\n}\n\nfunction InsightText({\n  as: Component = 'p',\n  className,\n  segments,\n}: {\n  /** @default 'p' */\n  as?: 'p' | 'span'\n  className?: string\n  segments: InsightSegment[]\n}) {\n  return (\n    <Component className={cn('text-sm leading-6 text-pretty', className)}>\n      {segments.map((segment, index) =>\n        typeof segment === 'string' ? (\n          segment\n        ) : (\n          <InsightHighlight key={index} tone={segment.tone}>\n            {segment.text}\n          </InsightHighlight>\n        ),\n      )}\n    </Component>\n  )\n}\n\nfunction insightToString(segments: InsightSegment[]) {\n  return segments\n    .map((segment) => (typeof segment === 'string' ? segment : segment.text))\n    .join('')\n}\n\ninterface InsightDriver {\n  label: string\n  /** Include the sign, such as \"+812\" or \"−14%\". */\n  value: string\n  /** @default 'neutral' */\n  tone?: InsightTone\n}\n\nfunction InsightDrivers({\n  className,\n  drivers,\n  label = 'Why',\n}: {\n  className?: string\n  drivers: InsightDriver[]\n  /** @default 'Why' */\n  label?: string\n}) {\n  if (drivers.length === 0) return null\n  return (\n    <div\n      className={cn('flex flex-wrap items-baseline gap-x-2 gap-y-1 text-xs', className)}\n    >\n      <span className='text-muted-foreground font-medium'>{label}</span>\n      <ul className='flex flex-wrap gap-x-3 gap-y-1'>\n        {drivers.map((driver) => (\n          <li key={driver.label} className='flex items-baseline gap-1'>\n            {driver.label}\n            <InsightHighlight tone={driver.tone}>{driver.value}</InsightHighlight>\n          </li>\n        ))}\n      </ul>\n    </div>\n  )\n}\n\nfunction getChangeTone(value: number, goodDirection: 'up' | 'down' = 'up'): InsightTone {\n  if (value === 0) return 'neutral'\n  return value > 0 === (goodDirection === 'up') ? 'positive' : 'negative'\n}\n\nexport {\n  InsightDrivers,\n  InsightHighlight,\n  InsightLabel,\n  InsightText,\n  getChangeTone,\n  insightKindConfig,\n  insightToString,\n}\n\nexport type {\n  InsightDriver,\n  InsightKind,\n  InsightKindConfig,\n  InsightMetric,\n  InsightSegment,\n  InsightTone,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/insights.tsx"
    }
  ],
  "type": "registry:component"
}
