{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "capability-matrix",
  "title": "Capability Matrix",
  "description": "One grid for what every AI bot can reach: click a cell to set no access, read or change, see risky permissions flagged, and save only what you edited.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/capability-matrix/capability-matrix.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type AccessLevel = \"none\" | \"read\" | \"write\";\n\nexport interface MatrixBot {\n  id: string;\n  name: string;\n  role: string;\n}\n\nexport interface MatrixTool {\n  id: string;\n  name: string;\n  /** Write access here counts as risky. */\n  sensitive?: boolean;\n}\n\nexport interface CapabilityMatrixProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  subtitle?: string;\n  bots?: MatrixBot[];\n  tools?: MatrixTool[];\n  /** Access by bot id, then tool id. Anything left out is none. */\n  access?: Record<string, Record<string, AccessLevel>>;\n  onSave?: (access: Record<string, Record<string, AccessLevel>>) => void;\n}\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst ACCENT = \"#5E6AD2\";\nconst ORANGE = \"#FC7840\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst ORDER: AccessLevel[] = [\"none\", \"read\", \"write\"];\nconst LABEL: Record<AccessLevel, string> = {\n  none: \"No access\",\n  read: \"Can read\",\n  write: \"Can change\",\n};\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    border: \"rgba(255,255,255,0.08)\",\n    grid: \"rgba(255,255,255,0.05)\",\n    ring: \"rgba(255,255,255,0.18)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    hover: \"rgba(255,255,255,0.04)\",\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.08)\",\n    grid: \"rgba(8,9,10,0.06)\",\n    ring: \"rgba(8,9,10,0.2)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.04)\",\n    hover: \"rgba(8,9,10,0.03)\",\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n  },\n};\n\nconst DEFAULT_BOTS: MatrixBot[] = [\n  { id: \"aria\", name: \"Aria\", role: \"Writer\" },\n  { id: \"sift\", name: \"Sift\", role: \"Support\" },\n  { id: \"tally\", name: \"Tally\", role: \"Finance\" },\n  { id: \"patch\", name: \"Patch\", role: \"Code\" },\n];\n\nconst DEFAULT_TOOLS: MatrixTool[] = [\n  { id: \"docs\", name: \"Docs\" },\n  { id: \"email\", name: \"Email\" },\n  { id: \"crm\", name: \"CRM\" },\n  { id: \"pay\", name: \"Billing\", sensitive: true },\n  { id: \"code\", name: \"Code\", sensitive: true },\n];\n\nconst DEFAULT_ACCESS: Record<string, Record<string, AccessLevel>> = {\n  aria: { docs: \"write\", email: \"read\", crm: \"read\" },\n  sift: { docs: \"read\", email: \"write\", crm: \"write\", pay: \"read\" },\n  tally: { docs: \"read\", crm: \"read\", pay: \"write\" },\n  patch: { docs: \"write\", code: \"write\" },\n};\n\n/** Empty, half or full, so the level reads without relying on colour. */\nfunction Level({\n  level,\n  color,\n  ring,\n}: {\n  level: AccessLevel;\n  color: string;\n  ring: string;\n}) {\n  return (\n    <svg\n      aria-hidden=\"true\"\n      width=\"18\"\n      height=\"18\"\n      viewBox=\"0 0 18 18\"\n      className=\"block\"\n    >\n      <circle\n        cx=\"9\"\n        cy=\"9\"\n        r=\"7.25\"\n        fill=\"none\"\n        stroke={level === \"none\" ? ring : color}\n        strokeWidth=\"1.5\"\n      />\n      {level === \"read\" && <path d=\"M9 4.5a4.5 4.5 0 0 1 0 9Z\" fill={color} />}\n      {level === \"write\" && <circle cx=\"9\" cy=\"9\" r=\"4.5\" fill={color} />}\n    </svg>\n  );\n}\n\nexport function CapabilityMatrix({\n  theme = \"dark\",\n  title = \"What each bot can reach\",\n  subtitle = \"Click a circle to change its access.\",\n  bots = DEFAULT_BOTS,\n  tools = DEFAULT_TOOLS,\n  access = DEFAULT_ACCESS,\n  onSave,\n  className,\n  style,\n  ...rest\n}: CapabilityMatrixProps) {\n  const c = PALETTES[theme];\n  const [changes, setChanges] = React.useState<Record<string, AccessLevel>>({});\n  const [saved, setSaved] = React.useState(access);\n\n  const original = (bot: string, tool: string): AccessLevel =>\n    saved[bot]?.[tool] ?? \"none\";\n  const levelOf = (bot: string, tool: string) =>\n    changes[`${bot}:${tool}`] ?? original(bot, tool);\n\n  const cells = bots.flatMap((b) =>\n    tools.map((t) => ({ bot: b, tool: t, level: levelOf(b.id, t.id) })),\n  );\n  const allowed = cells.filter((x) => x.level !== \"none\").length;\n  const risky = cells.filter(\n    (x) => x.tool.sensitive && x.level === \"write\",\n  ).length;\n  const edits = Object.keys(changes).length;\n\n  const cycle = (bot: string, tool: string) => {\n    const now = levelOf(bot, tool);\n    const next = ORDER[(ORDER.indexOf(now) + 1) % ORDER.length];\n    const key = `${bot}:${tool}`;\n    setChanges((prev) => {\n      const copy = { ...prev };\n      if (next === original(bot, tool)) delete copy[key];\n      else copy[key] = next;\n      return copy;\n    });\n  };\n\n  const save = () => {\n    const next: Record<string, Record<string, AccessLevel>> = {};\n    for (const b of bots) {\n      next[b.id] = {};\n      for (const t of tools) next[b.id][t.id] = levelOf(b.id, t.id);\n    }\n    setSaved(next);\n    setChanges({});\n    onSave?.(next);\n  };\n\n  return (\n    <section\n      aria-label={title}\n      className={`@container w-full rounded-2xl border ${className ?? \"\"}`}\n      style={{\n        background: c.card,\n        borderColor: c.border,\n        color: c.text,\n        fontFamily: FONT,\n        ...style,\n      }}\n      {...rest}\n    >\n      <div className=\"p-5 pb-3 @xl:p-6 @xl:pb-3\">\n        <div className=\"flex items-start justify-between gap-4\">\n          <header className=\"min-w-0\">\n            <h3 className=\"m-0 text-[20px] leading-[26px] font-[590] tracking-[-0.012em]\">\n              {title}\n            </h3>\n            <p\n              className=\"m-0 mt-1 text-[13px] leading-[20px] tracking-[-0.011em]\"\n              style={{ color: c.sub }}\n            >\n              {subtitle}\n            </p>\n          </header>\n          <div className=\"shrink-0 text-right\">\n            <p\n              aria-live=\"polite\"\n              className=\"m-0 text-[32px] leading-[32px] font-[510] tracking-[-0.022em] tabular-nums\"\n            >\n              {allowed}\n            </p>\n            <p\n              className=\"m-0 mt-1.5 text-[13px] leading-[20px] tabular-nums\"\n              style={{ color: c.sub }}\n            >\n              Of {cells.length} allowed\n            </p>\n          </div>\n        </div>\n        <div className=\"mt-3 flex flex-wrap items-center gap-x-3.5 gap-y-1\">\n          {ORDER.map((level) => (\n            <span\n              key={level}\n              className=\"flex items-center gap-1.5 text-[12.5px] leading-[18px] tracking-[-0.008em]\"\n              style={{ color: c.sub }}\n            >\n              <Level level={level} color={ACCENT} ring={c.ring} />\n              {LABEL[level]}\n            </span>\n          ))}\n        </div>\n      </div>\n\n      <div className=\"px-3 @xl:px-4\">\n        <table\n          className=\"w-full border-collapse\"\n          style={{ tableLayout: \"fixed\" }}\n        >\n          <thead>\n            <tr>\n              <th aria-label=\"Bot\" style={{ width: \"26%\" }} />\n              {tools.map((t) => (\n                <th\n                  key={t.id}\n                  scope=\"col\"\n                  className=\"truncate pb-2 text-center text-[12px] leading-[16px] font-normal tracking-[-0.005em]\"\n                  style={{ color: t.sensitive ? ORANGE : c.faint }}\n                >\n                  {t.name}\n                </th>\n              ))}\n            </tr>\n          </thead>\n          <tbody>\n            {bots.map((b) => (\n              <tr key={b.id} style={{ borderTop: `1px solid ${c.grid}` }}>\n                <th\n                  scope=\"row\"\n                  className=\"truncate py-2 pl-2 text-left font-normal\"\n                >\n                  <span className=\"block truncate text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em]\">\n                    {b.name}\n                  </span>\n                  <span\n                    className=\"block truncate text-[12px] leading-[16px] tracking-[-0.005em]\"\n                    style={{ color: c.faint }}\n                  >\n                    {b.role}\n                  </span>\n                </th>\n                {tools.map((t) => {\n                  const level = levelOf(b.id, t.id);\n                  const changed = `${b.id}:${t.id}` in changes;\n                  const danger = t.sensitive && level === \"write\";\n                  return (\n                    <td key={t.id} className=\"p-0 text-center\">\n                      <button\n                        type=\"button\"\n                        data-cell={`${b.id}-${t.id}`}\n                        aria-label={`${b.name}, ${t.name}: ${LABEL[level]}`}\n                        onClick={() => cycle(b.id, t.id)}\n                        className={`mx-auto flex cursor-pointer items-center justify-center rounded-lg border bg-transparent p-0 motion-safe:transition-colors motion-safe:duration-150 ${RING}`}\n                        style={{\n                          width: 38,\n                          height: 38,\n                          borderColor: changed ? ACCENT : \"transparent\",\n                        }}\n                      >\n                        <Level\n                          level={level}\n                          color={danger ? ORANGE : ACCENT}\n                          ring={c.ring}\n                        />\n                      </button>\n                    </td>\n                  );\n                })}\n              </tr>\n            ))}\n          </tbody>\n        </table>\n      </div>\n\n      <footer\n        className=\"mt-3 flex items-center justify-between gap-3 border-t px-5 py-3.5 @xl:px-6\"\n        style={{ borderColor: c.border }}\n      >\n        <p\n          aria-live=\"polite\"\n          className=\"m-0 min-w-0 truncate text-[13px] leading-[20px] tracking-[-0.011em] tabular-nums\"\n          style={{ color: risky ? ORANGE : c.sub }}\n        >\n          {risky} risky {risky === 1 ? \"permission\" : \"permissions\"}\n        </p>\n        <div className=\"flex shrink-0 gap-2\">\n          <button\n            type=\"button\"\n            data-reset=\"\"\n            disabled={!edits}\n            onClick={() => setChanges({})}\n            className={`h-9 cursor-pointer rounded-full border-0 px-4 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] disabled:cursor-default ${RING}`}\n            style={{ background: c.chip, color: edits ? c.soft : c.faint }}\n          >\n            Reset\n          </button>\n          <button\n            type=\"button\"\n            data-save=\"\"\n            disabled={!edits}\n            onClick={save}\n            className={`h-9 cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] tabular-nums disabled:cursor-default ${RING}`}\n            style={{\n              width: 112,\n              background: edits ? c.btn : c.chip,\n              color: edits ? c.btnText : c.faint,\n            }}\n          >\n            {edits ? `Save ${edits}` : \"No changes\"}\n          </button>\n        </div>\n      </footer>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}