{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scatter-04",
  "description": "Open risks on a likelihood by impact grid, shaded by level, with the risks in a selected cell listed.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/scatter.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/scatter/scatter-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  SkeletonText,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  type RiskLevel,\n  RiskLevelLabel,\n  getRiskLevel,\n  riskLevelConfig,\n} from '@/registry/components/dashboardblocks/scatter'\nimport { useState } from 'react'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ninterface Risk {\n  id: string\n  /** 1 (minor) to 5 (severe). */\n  impact: number\n  /** 1 (rare) to 5 (almost certain). */\n  likelihood: number\n  owner?: string\n  title: string\n}\n\ninterface Scatter4Props extends BlockStateProps {\n  description: string\n  /** Leave out, or pass none, to show the empty state. */\n  risks?: Risk[]\n  title: string\n}\n\nconst exampleProps: Scatter4Props = {\n  description: 'Open risks placed by how likely they are and how much they would hurt.',\n  risks: [\n    {\n      id: 'r1',\n      impact: 5,\n      likelihood: 3,\n      owner: 'Platform',\n      title: 'Primary database region outage',\n    },\n    {\n      id: 'r2',\n      impact: 4,\n      likelihood: 4,\n      owner: 'Security',\n      title: 'Leaked API keys in client builds',\n    },\n    {\n      id: 'r3',\n      impact: 3,\n      likelihood: 4,\n      owner: 'Growth',\n      title: 'Pricing change raises churn',\n    },\n    {\n      id: 'r4',\n      impact: 4,\n      likelihood: 2,\n      owner: 'Legal',\n      title: 'EU data residency deadline missed',\n    },\n    {\n      id: 'r5',\n      impact: 2,\n      likelihood: 4,\n      owner: 'Support',\n      title: 'Ticket backlog after launch',\n    },\n    {\n      id: 'r6',\n      impact: 3,\n      likelihood: 2,\n      owner: 'Platform',\n      title: 'Payment provider rate limits',\n    },\n    {\n      id: 'r7',\n      impact: 5,\n      likelihood: 1,\n      owner: 'Security',\n      title: 'Supply chain compromise',\n    },\n    {\n      id: 'r8',\n      impact: 1,\n      likelihood: 3,\n      owner: 'Design',\n      title: 'Icon set licence renewal',\n    },\n    {\n      id: 'r9',\n      impact: 3,\n      likelihood: 4,\n      owner: 'Mobile',\n      title: 'App store review delays',\n    },\n  ],\n  title: 'Risk matrix',\n}\n\nconst LIKELIHOOD = ['Rare', 'Unlikely', 'Possible', 'Likely', 'Almost certain']\nconst IMPACT = ['Minor', 'Moderate', 'Major', 'Severe', 'Critical']\nconst LEVELS: RiskLevel[] = ['critical', 'high', 'medium', 'low']\n\nconst Scatter4 = (props: Scatter4Props) => {\n  const { description, risks = [], errorMessage, status, title } = props\n  const state = getBlockState(status, risks)\n  const [selected, setSelected] = useState<{ impact: number; likelihood: number } | null>(\n    null,\n  )\n  const at = (likelihood: number, impact: number) =>\n    risks.filter((risk) => risk.likelihood === likelihood && risk.impact === impact)\n  const shown = selected\n    ? at(selected.likelihood, selected.impact)\n    : [...risks]\n        .sort((a, b) => b.likelihood * b.impact - a.likelihood * a.impact)\n        .slice(0, 3)\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <p className='text-muted-foreground text-sm'>{description}</p>\n            </header>\n            {state !== 'empty' && state !== 'error' && (\n              <ul className='flex flex-wrap gap-x-4 gap-y-1 border-t pt-4'>\n                {LEVELS.map((level) => (\n                  <li key={level} className='flex items-center gap-1.5'>\n                    <RiskLevelLabel level={level} />\n                    <span className='text-muted-foreground text-xs tabular-nums'>\n                      {state ? (\n                        <SkeletonText className='w-3' />\n                      ) : (\n                        risks.filter(\n                          (risk) => getRiskLevel(risk.likelihood, risk.impact) === level,\n                        ).length\n                      )}\n                    </span>\n                  </li>\n                ))}\n              </ul>\n            )}\n            <div className='grid grid-cols-[auto_repeat(5,minmax(0,1fr))] gap-1'>\n              {[5, 4, 3, 2, 1].map((likelihood) => (\n                <div key={likelihood} className='contents'>\n                  <span className='text-muted-foreground flex max-w-16 items-center pr-1 text-xs leading-tight @sm:max-w-none'>\n                    {LIKELIHOOD[likelihood - 1]}\n                  </span>\n                  {[1, 2, 3, 4, 5].map((impact) => {\n                    const cell = at(likelihood, impact)\n                    const level = getRiskLevel(likelihood, impact)\n                    const isSelected =\n                      selected?.likelihood === likelihood && selected.impact === impact\n                    return (\n                      <button\n                        key={impact}\n                        type='button'\n                        aria-label={`${LIKELIHOOD[likelihood - 1]} likelihood, ${IMPACT[impact - 1].toLowerCase()} impact: ${riskLevelConfig[level].label.toLowerCase()} risk${state ? '' : `, ${cell.length} ${cell.length === 1 ? 'risk' : 'risks'}`}`}\n                        aria-pressed={isSelected}\n                        disabled={Boolean(state)}\n                        className={cn(\n                          'ring-offset-background focus-visible:ring-foreground flex h-9 min-w-0 items-center @sm:aspect-[4/3] @sm:h-auto justify-center rounded-md text-sm font-semibold tabular-nums outline-none focus-visible:ring-2 focus-visible:ring-offset-1',\n                          riskLevelConfig[level].cell,\n                          isSelected && 'ring-foreground ring-2 ring-offset-1',\n                          (state || cell.length === 0) && 'text-transparent',\n                          state === 'loading' &&\n                            'animate-pulse motion-reduce:animate-none',\n                        )}\n                        onClick={() =>\n                          setSelected(isSelected ? null : { impact, likelihood })\n                        }\n                      >\n                        {cell.length}\n                      </button>\n                    )\n                  })}\n                </div>\n              ))}\n              <span />\n              {IMPACT.map((label) => (\n                <span\n                  key={label}\n                  className='text-muted-foreground truncate pt-1 text-center text-xs'\n                >\n                  {label}\n                </span>\n              ))}\n              <span />\n              <span className='text-muted-foreground col-span-5 text-center text-xs'>\n                Impact →\n              </span>\n            </div>\n            <div className='flex flex-col gap-1 border-t pt-4'>\n              <BlockReady className='text-sm'>\n                <span className='text-muted-foreground text-sm'>\n                  {selected\n                    ? `${LIKELIHOOD[selected.likelihood - 1]} and ${IMPACT[selected.impact - 1].toLowerCase()}.`\n                    : 'The three highest risks. Select a cell to see its risks.'}\n                </span>\n              </BlockReady>\n              {state ? (\n                <BlockStateRows rows={3} />\n              ) : shown.length === 0 ? (\n                <span className='text-muted-foreground py-2.5 text-sm'>\n                  No risks here.\n                </span>\n              ) : (\n                <ul className='flex flex-col'>\n                  {shown.map((risk) => (\n                    <li\n                      key={risk.id}\n                      className='flex items-center justify-between gap-3 border-b py-2.5 text-sm last:border-b-0'\n                    >\n                      <span className='min-w-0 truncate'>{risk.title}</span>\n                      <span className='flex shrink-0 items-center gap-2'>\n                        {risk.owner && (\n                          <span className='text-muted-foreground text-xs'>\n                            {risk.owner}\n                          </span>\n                        )}\n                        <RiskLevelLabel\n                          level={getRiskLevel(risk.likelihood, risk.impact)}\n                        />\n                      </span>\n                    </li>\n                  ))}\n                </ul>\n              )}\n            </div>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Scatter4, exampleProps as scatter4ExampleProps, type Risk, type Scatter4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/scatter/scatter-04.tsx"
    }
  ],
  "meta": {
    "shows": "Open risks on a likelihood by impact grid, shaded by level, with the risks in a selected cell listed.",
    "size": "full",
    "usedWith": [
      "alerts-01",
      "data-table-04"
    ],
    "component": "Scatter4",
    "props": "{ description: string; risks?: { id: string; impact: number; likelihood: number; owner?: string; title: string }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
