{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "security-02",
  "description": "Changes to access, keys and settings, newest first, with a switch to show warnings only.",
  "registryDependencies": [
    "button",
    "https://www.dashboardblocks.com/r/radix/activity-feed.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/details.json",
    "https://www.dashboardblocks.com/r/radix/security.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/security/security-02.tsx",
      "content": "'use client'\n\nimport { ActivityTime } from '@/registry/components/dashboardblocks/activity-feed'\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { Details } from '@/registry/components/dashboardblocks/details'\nimport {\n  type AuditSeverity,\n  AuditSeverityLabel,\n} from '@/registry/components/dashboardblocks/security'\nimport { useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\n\ninterface AuditEvent {\n  actor: string\n  action: string\n  at: Date\n  id: string\n  ip?: string\n  severity: AuditSeverity\n  target?: string\n}\n\ninterface Security2Props extends BlockStateProps {\n  /** Defaults to a sentence counting the changes and the critical ones. */\n  description?: string\n  /** Leave out, or pass none, to show the empty state. */\n  events?: AuditEvent[]\n  /** Pass a fixed date, so the block renders the same on the server and in the browser. */\n  now: Date\n  /** @default 'UTC' */\n  timeZone?: string\n  title: string\n}\n\nconst NOW = new Date(Date.UTC(2026, 8, 26, 16, 0))\nconst minutesAgo = (minutes: number) => new Date(NOW.getTime() - minutes * 60_000)\n\nconst exampleProps: Security2Props = {\n  events: [\n    {\n      action: 'created an API key',\n      actor: 'Kevin Moore',\n      at: minutesAgo(4),\n      id: 'a1',\n      ip: '203.0.113.24',\n      severity: 'info',\n      target: 'CI deploys',\n    },\n    {\n      action: 'changed the role of',\n      actor: 'Ana Lima',\n      at: minutesAgo(31),\n      id: 'a2',\n      ip: '198.51.100.7',\n      severity: 'warning',\n      target: 'Dana Kim to Admin',\n    },\n    {\n      action: 'turned off SSO enforcement',\n      actor: 'Ana Lima',\n      at: minutesAgo(35),\n      id: 'a3',\n      ip: '198.51.100.7',\n      severity: 'critical',\n    },\n    {\n      action: 'invited',\n      actor: 'Sara Okafor',\n      at: minutesAgo(120),\n      id: 'a4',\n      ip: '192.0.2.61',\n      severity: 'info',\n      target: 'tom@example.com',\n    },\n    {\n      action: 'exported the audit log',\n      actor: 'Kevin Moore',\n      at: minutesAgo(260),\n      id: 'a5',\n      ip: '203.0.113.24',\n      severity: 'info',\n    },\n    {\n      action: 'revoked the API key',\n      actor: 'Sara Okafor',\n      at: minutesAgo(1_500),\n      id: 'a6',\n      ip: '192.0.2.61',\n      severity: 'warning',\n      target: 'Old staging token',\n    },\n  ],\n  now: NOW,\n  title: 'Audit log',\n}\n\nconst summarize = (events: AuditEvent[]) => {\n  const critical = events.filter((event) => event.severity === 'critical').length\n  const changes = `${events.length} ${events.length === 1 ? 'change' : 'changes'} to access, keys and settings`\n  return critical > 0 ? `${changes}, ${critical} of them critical.` : `${changes}.`\n}\n\nconst Security2 = (props: Security2Props) => {\n  const { description, events = [], now, errorMessage, status, timeZone, title } = props\n  const [importantOnly, setImportantOnly] = useState(false)\n  const state = getBlockState(status, events)\n  const shown = importantOnly\n    ? events.filter((event) => event.severity !== 'info')\n    : events\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <section className='@container flex flex-col gap-3'>\n        <header className='flex flex-wrap items-start justify-between gap-3'>\n          <div className='flex flex-col gap-0.5'>\n            <h2 className='font-semibold tracking-tight'>{title}</h2>\n            {description ? (\n              <p className='text-muted-foreground text-sm'>{description}</p>\n            ) : (\n              <BlockReady className='text-sm'>\n                <p className='text-muted-foreground text-sm'>{summarize(events)}</p>\n              </BlockReady>\n            )}\n          </div>\n          <Button\n            aria-pressed={importantOnly}\n            disabled={state !== undefined}\n            size='sm'\n            variant={importantOnly ? 'secondary' : 'outline'}\n            onClick={() => setImportantOnly((value) => !value)}\n          >\n            Warnings only\n          </Button>\n        </header>\n        <BlockStateRows className='border-t' rows={6} />\n        {!state && (\n          <ol className='flex flex-col border-t'>\n            {shown.map((event) => (\n              <li\n                key={event.id}\n                className='flex items-start gap-3 border-b py-2.5 last:border-b-0'\n              >\n                <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n                  <p className='text-sm text-pretty'>\n                    <span className='font-medium'>{event.actor}</span> {event.action}\n                    {event.target && <span className='font-medium'> {event.target}</span>}\n                  </p>\n                  <Details className='text-muted-foreground text-xs'>\n                    <ActivityTime date={event.at} now={now} timeZone={timeZone} />\n                    {event.ip && <span className='font-mono'>{event.ip}</span>}\n                  </Details>\n                </div>\n                {event.severity !== 'info' && (\n                  <AuditSeverityLabel severity={event.severity} />\n                )}\n              </li>\n            ))}\n            {shown.length === 0 && (\n              <li className='text-muted-foreground py-6 text-center text-sm'>\n                No warnings in this log.\n              </li>\n            )}\n          </ol>\n        )}\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Security2,\n  exampleProps as security2ExampleProps,\n  type AuditEvent,\n  type Security2Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/security/security-02.tsx"
    }
  ],
  "meta": {
    "shows": "Changes to access, keys and settings, newest first, with a switch to show warnings only.",
    "size": "full",
    "usedWith": [
      "security-01",
      "security-03",
      "activity-feed-01"
    ],
    "component": "Security2",
    "props": "{ description?: string; events?: { actor: string; action: string; at: Date; id: string; ip?: string; severity: \"warning\" | \"info\" | \"critical\"; target?: string }[]; now: Date; timeZone?: string; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
