{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "status",
  "title": "Status",
  "description": "Primitives for service status: status levels written as a coloured dot and word, a legend, and a 90-day uptime bar with a tooltip for each day.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/status.tsx",
      "content": "'use client'\n\nimport { useBlockState } from '@/registry/components/dashboardblocks/block-state'\nimport {\n  ChartFloatingTooltip,\n  ChartPlaceholder,\n  ChartTooltipItem,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  StatusLabel,\n  type StatusTone,\n} from '@/registry/components/dashboardblocks/status-label'\nimport { type KeyboardEvent, type PointerEvent, useRef, useState } from 'react'\n\nimport { cn } from '@/lib/utils'\n\ntype StatusLevel =\n  | 'operational'\n  | 'degraded'\n  | 'partial'\n  | 'major'\n  | 'maintenance'\n  | 'unknown'\n\ninterface StatusConfig {\n  /** A CSS colour for marks drawn with `style`, such as a tooltip swatch. */\n  color: string\n  fill: string\n  label: string\n  /** The label where room is short, such as after a service's name on one line. */\n  shortLabel: string\n  /** Follows a service's name in a sentence, such as `is running slowly`. */\n  phrase: string\n  tone: StatusTone\n}\n\nconst statusConfig: Record<StatusLevel, StatusConfig> = {\n  operational: {\n    color: 'var(--color-emerald-500)',\n    fill: 'bg-emerald-500',\n    label: 'Operational',\n    shortLabel: 'Operational',\n    phrase: 'is operational',\n    tone: 'good',\n  },\n  degraded: {\n    color: 'var(--color-amber-400)',\n    fill: 'bg-amber-400',\n    label: 'Degraded performance',\n    shortLabel: 'Degraded',\n    phrase: 'is running slowly',\n    tone: 'warning',\n  },\n  partial: {\n    color: 'var(--color-orange-500)',\n    fill: 'bg-orange-500',\n    label: 'Partial outage',\n    shortLabel: 'Partial outage',\n    phrase: 'has a partial outage',\n    tone: 'bad',\n  },\n  major: {\n    color: 'var(--color-red-500)',\n    fill: 'bg-red-500',\n    label: 'Major outage',\n    shortLabel: 'Major outage',\n    phrase: 'is down',\n    tone: 'bad',\n  },\n  maintenance: {\n    color: 'var(--color-sky-500)',\n    fill: 'bg-sky-500',\n    label: 'Maintenance',\n    shortLabel: 'Maintenance',\n    phrase: 'is in maintenance',\n    tone: 'info',\n  },\n  unknown: {\n    color: 'color-mix(in oklab, var(--color-muted-foreground) 25%, transparent)',\n    fill: 'bg-muted-foreground/25',\n    label: 'No data',\n    shortLabel: 'No data',\n    phrase: 'isn’t reporting',\n    tone: 'neutral',\n  },\n}\n\n/** How a day draws in an uptime history: an operational day is light, so the days with an incident stand out. */\nfunction getDayFill(status: StatusLevel): Pick<StatusConfig, 'color' | 'fill'> {\n  if (status !== 'operational') return statusConfig[status]\n  return {\n    color: 'color-mix(in oklab, var(--color-emerald-500) 35%, transparent)',\n    fill: 'bg-emerald-500/35',\n  }\n}\n\nconst severityOrder: StatusLevel[] = [\n  'unknown',\n  'operational',\n  'maintenance',\n  'degraded',\n  'partial',\n  'major',\n]\n\nfunction getWorstStatus(statuses: StatusLevel[]): StatusLevel {\n  return statuses.reduce<StatusLevel>(\n    (worst, status) =>\n      severityOrder.indexOf(status) > severityOrder.indexOf(worst) ? status : worst,\n    'unknown',\n  )\n}\n\ninterface StatusIndicatorProps {\n  className?: string\n  hideLabel?: boolean\n  label?: string\n  status: StatusLevel\n}\n\nfunction StatusIndicator({\n  className,\n  hideLabel = false,\n  label,\n  status,\n}: StatusIndicatorProps) {\n  const config = statusConfig[status]\n  return (\n    <span\n      data-slot='status-indicator'\n      data-status={status}\n      className={cn('inline-flex items-center gap-2', className)}\n    >\n      {hideLabel ? (\n        <>\n          <span aria-hidden className={cn('size-2 shrink-0 rounded-full', config.fill)} />\n          <StatusLabel tone={config.tone} className='sr-only' variant='text'>\n            {label ?? config.label}\n          </StatusLabel>\n        </>\n      ) : (\n        <StatusLabel\n          tone={config.tone}\n          indicator={\n            <span\n              aria-hidden\n              className={cn('size-1.5 shrink-0 rounded-full', config.fill)}\n            />\n          }\n        >\n          {label ?? config.label}\n        </StatusLabel>\n      )}\n    </span>\n  )\n}\n\ninterface StatusLegendProps {\n  className?: string\n  statuses: StatusLevel[]\n}\n\nfunction StatusLegend({ className, statuses }: StatusLegendProps) {\n  return (\n    <ul\n      className={cn(\n        'text-muted-foreground flex flex-wrap items-center gap-x-4 gap-y-1 text-xs',\n        className,\n      )}\n    >\n      {statuses.map((status) => (\n        <li key={status} className='flex items-center gap-1.5'>\n          <span\n            aria-hidden\n            className={cn('h-2.5 w-1 rounded-[1px]', getDayFill(status).fill)}\n          />\n          {statusConfig[status].label}\n        </li>\n      ))}\n    </ul>\n  )\n}\n\ninterface UptimeDay {\n  label: string\n  note?: string\n  status: StatusLevel\n  /** Share of the day the service was up, 0–100. */\n  uptime?: number\n}\n\nfunction getUptime(days: UptimeDay[]) {\n  const measured = days.filter((day) => day.status !== 'unknown')\n  if (measured.length === 0) return 0\n  const total = measured.reduce(\n    (sum, day) => sum + (day.uptime ?? (day.status === 'major' ? 0 : 100)),\n    0,\n  )\n  return total / measured.length\n}\n\n/** Truncates rather than rounds, so any downtime never displays as 100%. */\nfunction formatUptime(value: number) {\n  if (value >= 100) return '100%'\n  return `${(Math.floor(value * 100) / 100).toFixed(2)}%`\n}\n\nfunction describeDay(day: UptimeDay | undefined) {\n  if (!day) return ''\n  const parts = [day.label, statusConfig[day.status].label]\n  if (day.uptime !== undefined && day.status !== 'unknown') {\n    parts.push(`${formatUptime(day.uptime)} uptime`)\n  }\n  if (day.note) parts.push(day.note)\n  return parts.join(', ')\n}\n\nconst UPTIME_BAR_HEIGHT = 32\n\ninterface UptimeBarProps {\n  className?: string\n  days: UptimeDay[]\n  label: string\n}\n\nfunction UptimeBar({ className, days, label }: UptimeBarProps) {\n  const [active, setActive] = useState<number | null>(null)\n  const [shown, setShown] = useState({ index: 0, x: 0 })\n  const ref = useRef<HTMLDivElement>(null)\n  const state = useBlockState()\n  const last = days.length - 1\n  const shownDay = days[shown.index]\n\n  if (state) {\n    return <ChartPlaceholder className={className} height={UPTIME_BAR_HEIGHT} />\n  }\n\n  const show = (index: number) => {\n    const width = ref.current?.offsetWidth ?? 0\n    setActive(index)\n    setShown({ index, x: ((index + 0.5) / days.length) * width })\n  }\n\n  const onPointerMove = (event: PointerEvent<HTMLDivElement>) => {\n    const rect = ref.current?.getBoundingClientRect()\n    if (!rect || days.length === 0) return\n    const ratio = (event.clientX - rect.left) / rect.width\n    show(Math.min(last, Math.max(0, Math.floor(ratio * days.length))))\n  }\n\n  const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {\n    const current = active ?? last\n    const next =\n      event.key === 'ArrowLeft'\n        ? current - 1\n        : event.key === 'ArrowRight'\n          ? current + 1\n          : event.key === 'Home'\n            ? 0\n            : event.key === 'End'\n              ? last\n              : null\n    if (next === null) return\n    event.preventDefault()\n    show(Math.min(last, Math.max(0, next)))\n  }\n\n  return (\n    <div className={cn('@container relative', className)}>\n      <div\n        ref={ref}\n        role='slider'\n        tabIndex={0}\n        aria-label={`${label}, daily status`}\n        aria-orientation='horizontal'\n        aria-valuemax={days.length}\n        aria-valuemin={1}\n        aria-valuenow={(active ?? last) + 1}\n        aria-valuetext={describeDay(days[active ?? last])}\n        style={{ height: UPTIME_BAR_HEIGHT }}\n        className='focus-visible:ring-ring/50 flex cursor-default gap-px rounded-[3px] outline-none focus-visible:ring-[3px] @md:gap-[2px]'\n        onBlur={() => setActive(null)}\n        onFocus={() => show(active ?? last)}\n        onKeyDown={onKeyDown}\n        onPointerLeave={() => setActive(null)}\n        onPointerMove={onPointerMove}\n      >\n        {days.map((day, index) => (\n          <span\n            key={`${day.label}-${index}`}\n            aria-hidden\n            className={cn(\n              'h-full min-w-0 flex-1 rounded-[2px] transition-opacity duration-150',\n              getDayFill(day.status).fill,\n              active !== null && active !== index && 'opacity-50',\n            )}\n          />\n        ))}\n      </div>\n      {shownDay && (\n        <ChartFloatingTooltip\n          active={active !== null}\n          flip={shown.index > days.length / 2}\n          x={shown.x}\n          y={UPTIME_BAR_HEIGHT}\n        >\n          <span className='font-medium'>{shownDay.label}</span>\n          <ChartTooltipItem\n            color={getDayFill(shownDay.status).color}\n            name={statusConfig[shownDay.status].label}\n            value={\n              shownDay.uptime !== undefined && shownDay.status !== 'unknown'\n                ? formatUptime(shownDay.uptime)\n                : ''\n            }\n          />\n          {shownDay.note && (\n            <span className='text-muted-foreground max-w-48'>{shownDay.note}</span>\n          )}\n        </ChartFloatingTooltip>\n      )}\n    </div>\n  )\n}\n\nexport {\n  StatusIndicator,\n  StatusLegend,\n  UptimeBar,\n  formatUptime,\n  getUptime,\n  getWorstStatus,\n  statusConfig,\n}\n\nexport type { StatusConfig, StatusLevel, UptimeBarProps, UptimeDay }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/status.tsx"
    }
  ],
  "type": "registry:component"
}
