{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "security-03",
  "description": "The devices signed in to an account, with where and when each was last active, and buttons to sign them out.",
  "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",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/security/security-03.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  useBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { Details } from '@/registry/components/dashboardblocks/details'\nimport {\n  DeviceIcon,\n  type DeviceKind,\n} from '@/registry/components/dashboardblocks/security'\nimport { StatusLabel } from '@/registry/components/dashboardblocks/status-label'\nimport { useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\n\ninterface Session {\n  client: string\n  current?: boolean\n  device: DeviceKind\n  id: string\n  lastActive: Date\n  location: string\n}\n\ninterface Security3Props extends BlockStateProps {\n  /** Defaults to a sentence counting the devices and where they are. */\n  description?: string\n  /** Pass a fixed date, so the block renders the same on the server and in the browser. */\n  now: Date\n  onSignOut?: (id: string) => void\n  /** Leave out, or pass none, to show the empty state. */\n  sessions?: Session[]\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: Security3Props = {\n  now: NOW,\n  sessions: [\n    {\n      client: 'Chrome on macOS',\n      current: true,\n      device: 'desktop',\n      id: 's1',\n      lastActive: NOW,\n      location: 'Lisbon, Portugal',\n    },\n    {\n      client: 'Safari on iOS',\n      device: 'mobile',\n      id: 's2',\n      lastActive: minutesAgo(42),\n      location: 'Lisbon, Portugal',\n    },\n    {\n      client: 'Firefox on Windows',\n      device: 'desktop',\n      id: 's3',\n      lastActive: minutesAgo(60 * 26),\n      location: 'Porto, Portugal',\n    },\n    {\n      client: 'Chrome on Android',\n      device: 'mobile',\n      id: 's4',\n      lastActive: minutesAgo(60 * 24 * 9),\n      location: 'Madrid, Spain',\n    },\n  ],\n  title: 'Active sessions',\n}\n\nconst summarize = (sessions: Session[]) => {\n  const places = new Set(sessions.map((session) => session.location)).size\n  const devices = `${sessions.length} ${sessions.length === 1 ? 'device' : 'devices'} signed in`\n  return places > 1 ? `${devices}, from ${places} places.` : `${devices}.`\n}\n\nfunction SessionList(props: Security3Props) {\n  const { now, onSignOut, timeZone, title } = props\n  const state = useBlockState()\n  const [sessions, setSessions] = useState(props.sessions ?? [])\n  const others = sessions.filter((session) => !session.current)\n\n  const signOut = (ids: string[]) => {\n    ids.forEach((id) => onSignOut?.(id))\n    setSessions((list) => list.filter((session) => !ids.includes(session.id)))\n  }\n\n  return (\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          {props.description ? (\n            <p className='text-muted-foreground text-sm'>{props.description}</p>\n          ) : (\n            <BlockReady className='text-sm'>\n              <p className='text-muted-foreground text-sm'>{summarize(sessions)}</p>\n            </BlockReady>\n          )}\n        </div>\n        {!state && others.length > 0 && (\n          <Button\n            size='sm'\n            variant='outline'\n            onClick={() => signOut(others.map((session) => session.id))}\n          >\n            Sign out others\n          </Button>\n        )}\n      </header>\n      <BlockStateRows className='border-t' rows={4} />\n      {!state && (\n        <ul className='flex flex-col border-t'>\n          {sessions.map((session) => (\n            <li\n              key={session.id}\n              className='flex items-center gap-3 border-b py-2.5 last:border-b-0'\n            >\n              <DeviceIcon kind={session.device} />\n              <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n                <span className='truncate text-sm font-medium'>{session.client}</span>\n                <Details className='text-muted-foreground text-xs'>\n                  {session.location}\n                  {session.current ? (\n                    'active now'\n                  ) : (\n                    <ActivityTime\n                      date={session.lastActive}\n                      now={now}\n                      timeZone={timeZone}\n                    />\n                  )}\n                </Details>\n              </div>\n              {session.current ? (\n                <StatusLabel tone='good'>This device</StatusLabel>\n              ) : (\n                <Button\n                  aria-label={`Sign out ${session.client} in ${session.location}`}\n                  size='sm'\n                  variant='ghost'\n                  onClick={() => signOut([session.id])}\n                >\n                  Sign out\n                </Button>\n              )}\n            </li>\n          ))}\n        </ul>\n      )}\n    </section>\n  )\n}\n\nconst Security3 = (props: Security3Props) => {\n  const { sessions = [], errorMessage, status } = props\n  const state = getBlockState(status, sessions)\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <SessionList key={state ?? 'ready'} {...props} />\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Security3,\n  exampleProps as security3ExampleProps,\n  type Security3Props,\n  type Session,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/security/security-03.tsx"
    }
  ],
  "meta": {
    "shows": "The devices signed in to an account, with where and when each was last active, and buttons to sign them out.",
    "size": "half",
    "usedWith": [
      "security-05",
      "security-02"
    ],
    "component": "Security3",
    "props": "{ description?: string; now: Date; onSignOut?: (id: string) => void; sessions?: { client: string; current?: boolean; device: \"desktop\" | \"mobile\"; id: string; lastActive: Date; location: string }[]; timeZone?: string; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
