{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "leaderboard-02",
  "description": "People ranked by revenue with a bar to their quota and the change since the last period.",
  "registryDependencies": [
    "card",
    "avatar",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/kpi.json",
    "https://www.dashboardblocks.com/r/radix/leaderboard.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/leaderboard/leaderboard-02.tsx",
      "content": "import {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { KPIChange } from '@/registry/components/dashboardblocks/kpi'\nimport {\n  Leaderboard,\n  LeaderboardItem,\n  LeaderboardLabel,\n  LeaderboardRank,\n  LeaderboardValue,\n} from '@/registry/components/dashboardblocks/leaderboard'\nimport {\n  formatCurrency,\n  formatPercent,\n  joinDetails,\n} from '@/registry/lib/dashboardblocks/format'\n\nimport { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ninterface SalesRep {\n  avatar: string\n  deals: number\n  id: number\n  name: string\n  /** Revenue target for the period, drawn as a mark on the rep's bar. */\n  quota: number\n  revenue: number\n  /** Percent change in revenue on the period before. */\n  trend: number\n}\n\ninterface Leaderboard2Props extends BlockStateProps {\n  currency?: string\n  /** Defaults to a sentence about the leader and how many reps passed quota. */\n  description?: string\n  /** Leave out, or pass none, to show the empty state. */\n  reps?: SalesRep[]\n  title: string\n}\n\nconst exampleProps: Leaderboard2Props = {\n  currency: 'USD',\n  reps: [\n    {\n      id: 1,\n      name: 'Sarah Chen',\n      avatar: '/images/avatar-11.webp',\n      deals: 42,\n      quota: 150_000,\n      revenue: 184_300,\n      trend: 12.4,\n    },\n    {\n      id: 2,\n      name: 'Marcus Reid',\n      avatar: '/images/avatar-04.webp',\n      deals: 37,\n      quota: 150_000,\n      revenue: 156_900,\n      trend: 8.1,\n    },\n    {\n      id: 3,\n      name: 'Priya Patel',\n      avatar: '/images/avatar-02.webp',\n      deals: 33,\n      quota: 125_000,\n      revenue: 139_450,\n      trend: -2.3,\n    },\n    {\n      id: 4,\n      name: 'Diego Alvarez',\n      avatar: '/images/avatar-13.webp',\n      deals: 28,\n      quota: 125_000,\n      revenue: 118_200,\n      trend: 4.6,\n    },\n    {\n      id: 5,\n      name: 'Emma Larsen',\n      avatar: '/images/avatar-03.webp',\n      deals: 24,\n      quota: 125_000,\n      revenue: 97_750,\n      trend: 0,\n    },\n  ],\n  title: 'Top performers',\n}\n\nfunction getInitials(name: string) {\n  return name\n    .split(/\\s+/)\n    .filter(Boolean)\n    .slice(0, 2)\n    .map((part) => part[0]?.toUpperCase())\n    .join('')\n}\n\nfunction summarize(reps: SalesRep[], format: (value: number) => string) {\n  const [first, second] = reps\n  if (!first) return 'No closed deals yet.'\n  const lead = second\n    ? `${first.name} leads with ${format(first.revenue)}, ${format(first.revenue - second.revenue)} ahead of ${second.name}.`\n    : `${first.name} leads with ${format(first.revenue)}.`\n  const past = reps.filter((rep) => rep.revenue >= rep.quota).length\n  return `${lead} ${past} of ${reps.length} ${reps.length === 1 ? 'rep' : 'reps'} ${past === 1 ? 'is' : 'are'} past quota.`\n}\n\nconst Leaderboard2 = (props: Leaderboard2Props) => {\n  const { currency = 'USD', reps = [], errorMessage, status, title } = props\n  const state = getBlockState(status, reps)\n  const format = (value: number) => formatCurrency(value, { currency })\n  const { description = summarize(reps, format) } = props\n  const scale = Math.max(...reps.map((rep) => rep.revenue / (rep.quota || 1)), 1)\n\n  return (\n    <Card>\n      <CardContent>\n        <BlockStateProvider errorMessage={errorMessage} state={state}>\n          <section className='@container flex flex-col gap-3'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <BlockReady className='text-sm'>\n                <p className='text-muted-foreground text-sm'>{description}</p>\n              </BlockReady>\n            </header>\n            <BlockStateRows className='border-t' rows={5} />\n            {!state && (\n              <Leaderboard className='gap-0 border-t'>\n                {reps.map((rep, index) => {\n                  const attainment = rep.revenue / (rep.quota || 1)\n                  return (\n                    <LeaderboardItem\n                      key={rep.id}\n                      size='lg'\n                      className='items-start border-b px-0 py-3 last:border-b-0'\n                    >\n                      <LeaderboardRank rank={index + 1} className='mt-2.5' />\n                      <Avatar\n                        // Not the primitive's colour: the style sets no outline, so this one is the block's own\n                        className='size-9 outline outline-1 -outline-offset-1 outline-black/10 dark:outline-white/10'\n                      >\n                        <AvatarImage src={rep.avatar} alt='' />\n                        <AvatarFallback className='text-xs'>\n                          {getInitials(rep.name)}\n                        </AvatarFallback>\n                      </Avatar>\n                      <LeaderboardLabel className='flex flex-col gap-1.5'>\n                        <div>\n                          <p className='truncate font-medium'>{rep.name}</p>\n                          <p className='text-muted-foreground text-xs tabular-nums'>\n                            {joinDetails(\n                              `${rep.deals} deals`,\n                              `${formatPercent(attainment, { maximumFractionDigits: 0 })} of quota`,\n                            )}\n                          </p>\n                        </div>\n                        <div\n                          aria-hidden='true'\n                          className='bg-muted relative h-1 rounded-full'\n                        >\n                          <div\n                            className={cn(\n                              'h-full rounded-full',\n                              attainment >= 1\n                                ? 'bg-chart-2'\n                                : 'bg-[color-mix(in_oklab,var(--color-chart-2)_30%,transparent)]',\n                            )}\n                            style={{ width: `${(attainment / scale) * 100}%` }}\n                          />\n                          <div\n                            className='bg-foreground absolute -top-1 -bottom-1 w-px'\n                            style={{ insetInlineStart: `${(1 / scale) * 100}%` }}\n                          />\n                        </div>\n                      </LeaderboardLabel>\n                      <LeaderboardValue className='flex flex-col items-end gap-0.5'>\n                        <span>{format(rep.revenue)}</span>\n                        <KPIChange\n                          className='text-xs font-normal'\n                          comparison='last period'\n                          inline\n                          previous={rep.revenue / (1 + rep.trend / 100)}\n                          value={rep.revenue}\n                          variant='short'\n                        />\n                      </LeaderboardValue>\n                    </LeaderboardItem>\n                  )\n                })}\n              </Leaderboard>\n            )}\n            {state !== 'empty' && state !== 'error' && (\n              <p\n                aria-hidden='true'\n                className='text-muted-foreground flex items-center gap-2 text-xs'\n              >\n                <span className='bg-foreground h-3 w-px' />\n                The line on each bar is the rep&apos;s quota.\n              </p>\n            )}\n          </section>\n        </BlockStateProvider>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport {\n  Leaderboard2,\n  exampleProps as leaderboard2ExampleProps,\n  type Leaderboard2Props,\n  type SalesRep,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/leaderboard/leaderboard-02.tsx"
    }
  ],
  "meta": {
    "shows": "People ranked by revenue with a bar to their quota and the change since the last period.",
    "size": "half",
    "usedWith": [
      "team-01",
      "leaderboard-04",
      "chart-panel-01"
    ],
    "component": "Leaderboard2",
    "props": "{ currency?: string; description?: string; reps?: { avatar: string; deals: number; id: number; name: string; quota: number; revenue: number; trend: number }[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
