{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "realtime-01",
  "description": "Active users now, page views per second over the last minute and the pages with the most people on them.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json",
    "https://www.dashboardblocks.com/r/radix/leaderboard.json",
    "https://www.dashboardblocks.com/r/radix/realtime.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/realtime/realtime-01.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { KPIValue } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  Leaderboard,\n  LeaderboardBar,\n  LeaderboardItem,\n  LeaderboardLabel,\n  LeaderboardValue,\n} from '@/registry/components/dashboardblocks/leaderboard'\nimport {\n  LiveBadge,\n  LiveNumber,\n  RollingBars,\n  createRandom,\n} from '@/registry/components/dashboardblocks/realtime'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\ninterface ActivePage {\n  path: string\n  users: number\n}\n\ninterface Realtime1Props extends BlockStateProps {\n  /** Leave out to show the empty state. */\n  activeUsers?: number\n  description: string\n  /** Page views per second over the last minute, oldest first. */\n  pageViews?: number[]\n  pages?: ActivePage[]\n  title: string\n}\n\nconst seed = createRandom(7)\n\nconst exampleProps: Realtime1Props = {\n  activeUsers: 1_284,\n  description: 'People on the site in the last 5 minutes, and the pages they are on.',\n  pageViews: Array.from({ length: 60 }, () => Math.round(28 + seed() * 34)),\n  pages: [\n    { path: '/pricing', users: 312 },\n    { path: '/', users: 268 },\n    { path: '/docs/quickstart', users: 194 },\n    { path: '/blog/launch-week', users: 151 },\n    { path: '/changelog', users: 87 },\n  ],\n  title: 'Right now',\n}\n\nconst noViews: number[] = []\nconst noPages: ActivePage[] = []\n\nconst Realtime1 = (props: Realtime1Props) => {\n  const {\n    activeUsers: users = 0,\n    description,\n    pageViews: views = noViews,\n    pages = noPages,\n    errorMessage,\n    status,\n    title,\n  } = props\n  const state = getBlockState(status, props.activeUsers)\n\n  const perMinute = views.slice(-60).reduce((sum, value) => sum + value, 0)\n  const top = Math.max(1, ...pages.map((page) => page.users))\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\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 && <LiveBadge />}\n            </header>\n            <div className='flex flex-col gap-3 border-t pt-4'>\n              <div className='flex flex-wrap items-end justify-between gap-x-4 gap-y-2'>\n                <div className='flex flex-col gap-1'>\n                  <span className='text-muted-foreground text-sm'>Active users</span>\n                  {state ? (\n                    <KPIValue />\n                  ) : (\n                    <span className='text-4xl font-light tracking-tight'>\n                      <LiveNumber value={users} />\n                    </span>\n                  )}\n                </div>\n                {state !== 'error' && state !== 'empty' && (\n                  <div className='flex flex-col items-end gap-1'>\n                    <span className='text-muted-foreground text-sm'>\n                      Page views, last minute\n                    </span>\n                    {state ? (\n                      <KPIValue className='text-2xl' />\n                    ) : (\n                      <span className='text-2xl font-light tracking-tight'>\n                        <LiveNumber value={perMinute} />\n                      </span>\n                    )}\n                  </div>\n                )}\n              </div>\n              <div className='flex flex-col gap-1'>\n                <RollingBars\n                  height={56}\n                  labels={views.map((_, index) => `${views.length - 1 - index}s ago`)}\n                  values={views}\n                />\n                {!state && (\n                  <div\n                    aria-hidden\n                    className='text-muted-foreground flex justify-between text-xs'\n                  >\n                    <span>{views.length}s ago</span>\n                    <span>Now</span>\n                  </div>\n                )}\n              </div>\n            </div>\n            {state !== 'error' && state !== 'empty' && (\n              <div className='flex flex-col gap-1.5'>\n                <div className='text-muted-foreground flex justify-between px-2 text-xs'>\n                  <span>Top pages</span>\n                  <span>Users</span>\n                </div>\n                {state === 'loading' && <BlockStateRows rows={5} />}\n                {!state && (\n                  <Leaderboard>\n                    {pages.map((page, index) => (\n                      <LeaderboardItem key={page.path}>\n                        <LeaderboardBar\n                          className={\n                            index === 0\n                              ? 'bg-[color-mix(in_oklab,var(--color-chart-2)_32%,transparent)]'\n                              : undefined\n                          }\n                          value={(page.users / top) * 100}\n                        />\n                        <LeaderboardLabel className='truncate'>\n                          {page.path}\n                        </LeaderboardLabel>\n                        <LeaderboardValue>\n                          <LiveNumber value={page.users} />\n                        </LeaderboardValue>\n                      </LeaderboardItem>\n                    ))}\n                  </Leaderboard>\n                )}\n              </div>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Realtime1,\n  exampleProps as realtime1ExampleProps,\n  type ActivePage,\n  type Realtime1Props,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/realtime/realtime-01.tsx"
    }
  ],
  "meta": {
    "shows": "Active users now, page views per second over the last minute and the pages with the most people on them.",
    "size": "compact",
    "usedWith": [
      "chart-panel-02",
      "geo-03"
    ],
    "component": "Realtime1",
    "props": "{ activeUsers?: number; description: string; pageViews?: number[]; pages?: { path: string; users: number }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
