{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "security-04",
  "description": "A security score on a banded gauge, built from workspace checks, with failing checks first and what to do about each.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/gauge.json",
    "https://www.dashboardblocks.com/r/radix/security.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/security/security-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  Gauge,\n  type GaugeBand,\n  GaugeToneLabel,\n  GaugeValue,\n  getGaugeBand,\n} from '@/registry/components/dashboardblocks/gauge'\nimport {\n  type CheckResult,\n  CheckResultLabel,\n  getSecurityScore,\n} from '@/registry/components/dashboardblocks/security'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface SecurityCheck {\n  detail: string\n  id: string\n  label: string\n  result: CheckResult\n  weight?: number\n}\n\ninterface Security4Props extends BlockStateProps {\n  /** Leave out, or pass none, to show the empty state. */\n  checks?: SecurityCheck[]\n  description: string\n  title: string\n}\n\nconst exampleProps: Security4Props = {\n  checks: [\n    {\n      detail: '87% of members, 4 admins without it',\n      id: 'mfa',\n      label: 'Multi-factor authentication',\n      result: 'warn',\n      weight: 3,\n    },\n    {\n      detail: 'Turned off 35 minutes ago',\n      id: 'sso',\n      label: 'SSO enforced',\n      result: 'fail',\n      weight: 2,\n    },\n    {\n      detail: '2 keys unused for over 90 days',\n      id: 'keys',\n      label: 'API keys rotated',\n      result: 'warn',\n    },\n    {\n      detail: 'Last 30 days exported to your SIEM',\n      id: 'audit',\n      label: 'Audit log streaming',\n      result: 'pass',\n    },\n    {\n      detail: 'Only from approved domains',\n      id: 'domains',\n      label: 'Invite restrictions',\n      result: 'pass',\n    },\n    {\n      detail: 'Sessions expire after 12 hours',\n      id: 'sessions',\n      label: 'Session timeout',\n      result: 'pass',\n    },\n  ],\n  description: 'Workspace settings checked against recommended practice.',\n  title: 'Security posture',\n}\n\nconst BANDS: GaugeBand[] = [\n  { from: 0, label: 'At risk', to: 60, tone: 'critical' },\n  { from: 60, label: 'Needs work', to: 80, tone: 'caution' },\n  { from: 80, label: 'Good', to: 100, tone: 'positive' },\n]\n\nconst ORDER: Record<CheckResult, number> = { fail: 0, pass: 2, warn: 1 }\n\nconst countChecks = (count: number) => `${count} ${count === 1 ? 'check' : 'checks'}`\n\nconst Security4 = (props: Security4Props) => {\n  const { checks = [], description, errorMessage, status, title } = props\n  const state = getBlockState(status, checks)\n  const score = getSecurityScore(checks)\n  const band = getGaugeBand(score, BANDS)\n  const sorted = [...checks].sort((a, b) => ORDER[a.result] - ORDER[b.result])\n  const failing = checks.filter((check) => check.result === 'fail').length\n  const warnings = checks.filter((check) => check.result === 'warn').length\n  const passing = checks.length - failing - warnings\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider errorMessage={errorMessage} state={state}>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex items-start justify-between gap-3'>\n              <div className='flex min-w-0 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              </div>\n              {!state && band && (\n                <GaugeToneLabel className='mt-0.5' label={band.label} tone={band.tone} />\n              )}\n            </header>\n            <div className='flex items-center gap-5 border-t pt-4'>\n              <Gauge\n                bands={BANDS}\n                className='w-full max-w-32 shrink-0'\n                colorByBand\n                label={title}\n                sweep={270}\n                thickness={11}\n                value={score}\n                valueText={`${score} out of 100${band ? `, ${band.label.toLowerCase()}` : ''}`}\n              >\n                <GaugeValue className='text-3xl'>{score}</GaugeValue>\n                {!state && (\n                  <span className='text-muted-foreground text-xs'>out of 100</span>\n                )}\n              </Gauge>\n              <BlockReady className='w-full text-sm'>\n                <p className='text-sm text-pretty'>\n                  {failing > 0 ? (\n                    <span className='font-medium text-red-700 dark:text-red-400'>\n                      {countChecks(failing)} failing\n                    </span>\n                  ) : (\n                    <span className='font-medium'>Nothing failing</span>\n                  )}\n                  {warnings > 0 && <>, {countChecks(warnings)} to look at</>}.{' '}\n                  <span className='text-muted-foreground'>\n                    {passing} of {checks.length} pass.\n                  </span>\n                </p>\n              </BlockReady>\n            </div>\n            {state === 'loading' && <BlockStateRows className='border-t' rows={6} />}\n            {!state && (\n              <ul className='flex flex-col border-t'>\n                {sorted.map((check) => (\n                  <li\n                    key={check.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                      <span className='text-sm font-medium'>{check.label}</span>\n                      <span className='text-muted-foreground text-xs'>\n                        {check.detail}\n                      </span>\n                    </div>\n                    <CheckResultLabel result={check.result} />\n                  </li>\n                ))}\n              </ul>\n            )}\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport {\n  Security4,\n  exampleProps as security4ExampleProps,\n  type Security4Props,\n  type SecurityCheck,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/security/security-04.tsx"
    }
  ],
  "meta": {
    "shows": "A security score on a banded gauge, built from workspace checks, with failing checks first and what to do about each.",
    "size": "half",
    "usedWith": [
      "security-05",
      "security-06",
      "security-01"
    ],
    "component": "Security4",
    "props": "{ checks?: { detail: string; id: string; label: string; result: \"pass\" | \"warn\" | \"fail\"; weight?: number }[]; description: string; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
