{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "alerts-04",
  "description": "A slim strip with open alerts by severity and the latest one, for the top of a dashboard.",
  "registryDependencies": [
    "card",
    "button",
    "https://www.dashboardblocks.com/r/radix/alerts.json",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/details.json",
    "https://www.dashboardblocks.com/r/radix/format.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/alerts/alerts-04.tsx",
      "content": "'use client'\n\nimport {\n  type AlertSeverity,\n  SeverityLabel,\n  severityConfig,\n} from '@/registry/components/dashboardblocks/alerts'\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateText,\n  type BlockStateProps,\n  SkeletonText,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { Details } from '@/registry/components/dashboardblocks/details'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatRelativeTime } from '@/registry/lib/dashboardblocks/format'\n\nimport { Button } from '@/components/ui/button'\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface Alerts4Props extends BlockStateProps {\n  /** Leave out to show the empty state. */\n  counts?: Partial<Record<Exclude<AlertSeverity, 'resolved'>, number>>\n  latest?: {\n    firedAt: Date\n    severity: AlertSeverity\n    source: string\n    title: string\n  }\n  now: Date\n  onViewAll?: () => void\n}\n\nconst NOW = Date.UTC(2026, 8, 25, 14, 30)\n\nconst exampleProps: Alerts4Props = {\n  counts: { critical: 2, info: 3, warning: 5 },\n  latest: {\n    firedAt: new Date(NOW - 4 * 60_000),\n    severity: 'critical',\n    source: 'checkout-api',\n    title: 'Error rate above 5% for 10 minutes',\n  },\n  now: new Date(NOW),\n}\n\nconst SEVERITIES = ['critical', 'warning', 'info'] as const\n\nconst Alerts4 = (props: Alerts4Props) => {\n  const { counts, latest, now, onViewAll, errorMessage, status } = props\n  const state = getBlockState(status, counts)\n  const total = SEVERITIES.reduce((sum, severity) => sum + (counts?.[severity] ?? 0), 0)\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider errorMessage={errorMessage} state={state}>\n          <section className='@container flex flex-col gap-3 border-t pt-3 in-data-[slot=card]:first:border-t-0 in-data-[slot=card]:first:pt-0 @2xl:flex-row @2xl:items-center @2xl:gap-6'>\n            <div className='flex shrink-0 flex-col gap-0.5'>\n              {state === 'error' || state === 'empty' ? (\n                <p className='flex items-baseline gap-2'>\n                  <span className='text-sm font-medium'>Open alerts</span>\n                  <BlockStateText\n                    className='text-2xl font-light tracking-tight'\n                    variant='short'\n                  />\n                </p>\n              ) : (\n                <p className='flex items-baseline gap-2'>\n                  <span className='text-2xl font-light tracking-tight tabular-nums'>\n                    {state === 'loading' ? <SkeletonText className='w-[1.5em]' /> : total}\n                  </span>\n                  <span className='text-sm font-medium'>\n                    {total === 1 ? 'open alert' : 'open alerts'}\n                  </span>\n                </p>\n              )}\n              <BlockReady className='w-40 text-sm'>\n                <Details className='text-sm'>\n                  {SEVERITIES.map((severity) => {\n                    const count = counts?.[severity] ?? 0\n                    return count > 0 ? (\n                      <SeverityLabel variant='text' key={severity} severity={severity}>\n                        {count} {severityConfig[severity].label.toLowerCase()}\n                      </SeverityLabel>\n                    ) : (\n                      <span key={severity} className='text-muted-foreground tabular-nums'>\n                        0 {severityConfig[severity].label.toLowerCase()}\n                      </span>\n                    )\n                  })}\n                </Details>\n              </BlockReady>\n            </div>\n            {state === 'loading' && (\n              <BlockReady className='min-w-0 flex-1 text-sm @2xl:border-l @2xl:pl-6'>\n                {null}\n              </BlockReady>\n            )}\n            {!state && (\n              <div className='flex min-w-0 flex-1 flex-col gap-0.5 text-sm @2xl:border-l @2xl:pl-6'>\n                {latest && total > 0 ? (\n                  <>\n                    <p>\n                      <span className='text-muted-foreground'>Latest </span>\n                      <SeverityLabel severity={latest.severity} />{' '}\n                      <span className='font-medium'>{latest.title}</span>\n                    </p>\n                    <Details className='text-muted-foreground text-xs'>\n                      {latest.source}\n                      <time dateTime={latest.firedAt.toISOString()}>\n                        {formatRelativeTime(latest.firedAt, now)}\n                      </time>\n                    </Details>\n                  </>\n                ) : (\n                  <p className='text-muted-foreground'>Nothing needs a response.</p>\n                )}\n              </div>\n            )}\n            <Button\n              variant='outline'\n              size='sm'\n              className='self-start @2xl:self-center'\n              onClick={onViewAll}\n            >\n              View alerts\n              <IconPlaceholder\n                lucide='ArrowRightIcon'\n                tabler='IconArrowRight'\n                hugeicons='ArrowRight01Icon'\n                phosphor='ArrowRightIcon'\n                remixicon='RiArrowRightLine'\n                data-icon='inline-end'\n              />\n            </Button>\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport { Alerts4, exampleProps as alerts4ExampleProps, type Alerts4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/alerts/alerts-04.tsx"
    }
  ],
  "meta": {
    "shows": "A slim strip with open alerts by severity and the latest one, for the top of a dashboard.",
    "size": "full",
    "usedWith": [
      "alerts-01",
      "stat-group-02",
      "status-01"
    ],
    "component": "Alerts4",
    "props": "{ counts?: { warning?: number; info?: number; critical?: number }; latest?: { firedAt: Date; severity: \"resolved\" | \"warning\" | \"info\" | \"critical\"; source: string; title: string }; now: Date; onViewAll?: () => void; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
